简体   繁体   中英

How to setup google cloud Cloudbuild.yaml to replicate a jenkins job?

I have the following script thats run in my jenkins job

set +x
SERVICE_ACCOUNT=`cat "$GCLOUD_AUTH_FILE"`
docker login -u _json_key -p "${SERVICE_ACCOUNT}" https://gcr.io
set -x

docker pull gcr.io/$MYPROJECT/automation:master

docker run --rm --attach STDOUT -v "$(pwd)":/workspace -v "$GCLOUD_AUTH_FILE":/gcloud-auth/service_account_key.json -v /var/run/docker.sock:/var/run/docker.sock -e "BRANCH=master" -e "PROJECT=myproject" gcr.io/myproject/automation:master "/building/buildImages.sh" "myapp"

if [ $? -ne 0 ]; then
  exit 1
fi

I am now trying to do this in cloudbuild.yaml such that I can run my script using my own automation image (which has a bunch of dependencies docker/jdk/pip etc installed), and mount my git folders in my workspace directory

I tried putting my cloudbuild.yaml at the top level in my directory in my git repo and set it up as this

steps:
- name: 'gcr.io/myproject/automation:master'
  volumes:
  - name: 'current-working-dir'
    path: /mydirectory
  args: ['bash', '-c','/building/buildImages.sh', 'myapp']
timeout: 4000s

But this gives me errors saying the invalid build: Volume "current-working-dir" is only used by one step

Just FYI, my script buildImages.sh, copies folders and dockerfiles, runs pip install/ npm/ and gradle commands and then docker build commands (kind of all in one solution).

Whats the way to translate my script to cloudbuild.yaml

try this in your cloudbuild.yaml:

steps:
- name: 'gcr.io/<your-project>/<image>'
  args: ['sh','<your-script>.sh']

using this I was able to pull the image from Google Cloud Registry that has my script, then run the script using 'sh'. It didn't matter where the script is. I'm using alpine in my Dockerfile as base image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM