Server安裝

mkdir -p /dcoker_data/gocd/data
mkdir -p /dcoker_data/gocd/home
docker run -d --name GoCD -v /dcoker_data/gocd/data:/godata -v /dcoker_data/gocd/home:/home/go -p8153:8153 -p8154:8154 gocd/gocd-server:v18.10.0
chown -R 1000 /dcoker_data/gocd

plugin

curl --location --fail https://example.com/plugin.jar > /path/to/godata/plugins/external/plugin.jar
chown -R 1000 /godata/plugins/external

git

http://account:passwd@host/xxxx.git

Agent安裝

Rebulid Docker

  • Dockerfile for mvn
FROM host/gocd/gocd-agent-alpine-3.8:v18.10.0

ARG ver=v18.10.1

LABEL maintainer="xyzqb"
LABEL version=$ver
LABEL description="GoCD Agent"

RUN ["apk","add","maven"]
RUN ["apk","add","-u","openjdk8"]


COPY settings.xml  /usr/share/java/maven-3/conf/

ENV M2_HOME="/usr/share/java/maven-3"
ENV JAVA_HOME="/usr/lib/jvm/default-jvm"
ENV PATH="${PATH}:${JAVA_HOME}/bin"
  • Dockerfile for docker daemon
FROM host/gocd/gocd-agent-alpine-3.8:v18.10.1

ARG ver=v18.10.2
ARG dgid=992

RUN ["apk","add","docker"]
RUN ["apk","add","jq"]
RUN /bin/sh -c 'addgroup -g $dgid docker2'
RUN ["adduser","go","docker2"]

  • docker push權限
    su - go;docker login -u user host

Config

Paramater

設定 VAR=abc,可在組態環境中用 #{VAR} 取得

TASK

stop docker

/bin/sh -c "test $(docker ps  -f 'name=my_container' -q) && docker stop my_container;docker rm my_container || echo no"

Fetch Artifact

取得其它stage產生的資料

Docker build

不同環境下的問題
  • shell 沒有執行權 chmod u+x shell.sh
  • 換行符號不同 dos2unix shell.sh

SonarQube quality檢測

/bin/sh -c "test $(curl http://xxx.xxx.xxx.xxx:9000/api/qualitygates/project_status?projectKey=tw.newegg.test:Reactive|jq -r '.projectStatus.status') == 'OK' && exit 0 || exit 1"
PS:需要等一下sonarqube server變更狀態,sonar:sonar後中間可加個sleep 5的task

透過sh 刪除 none docker images

shell

#!/bin/sh

IMAGES=`docker images -f "dangling=true" -q`

if expr "$IMAGES"
then
docker rmi $(docker images -f "dangling=true" -q)
else
echo "Not removed images."
fi

run with go user