diff --git a/services/auto-scan/cloudbuild.yaml b/services/auto-scan/cloudbuild.yaml index c08bc649bf..b10c2495ef 100755 --- a/services/auto-scan/cloudbuild.yaml +++ b/services/auto-scan/cloudbuild.yaml @@ -15,28 +15,40 @@ steps: args: ["-c", "pip3 install -r requirements.txt && python3 -m pytest"] - name: 'gcr.io/cloud-builders/docker' - id: build-auto-scan-if-master + id: generate-image-name entrypoint: 'bash' dir: services/auto-scan args: - - '-c' - - | - if [[ "$BRANCH_NAME" == "master" ]] - then - docker build -t gcr.io/$PROJECT_ID/services/autoscan:$BRANCH_NAME-$SHORT_SHA . - else - exit 0 - fi + - '-c' + - | + echo "gcr.io/$PROJECT_ID/services/autoscan:$BRANCH_NAME-$SHORT_SHA-$(date +%s)" > /workspace/imagename - name: 'gcr.io/cloud-builders/docker' - id: push-auto-scan-if-master + id: build-if-master entrypoint: 'bash' + dir: services/auto-scan + args: + - '-c' + - | + if [[ "$BRANCH_NAME" == "master" ]] + then + image=$(cat /workspace/imagename) + docker build -t $image . + else + exit 0 + fi + + - name: 'gcr.io/cloud-builders/docker' + id: push-if-master + entrypoint: 'bash' + dir: services/auto-scan args: - - '-c' - - | - if [[ "$BRANCH_NAME" == "master" ]] - then - docker push gcr.io/$PROJECT_ID/services/autoscan:$BRANCH_NAME-$SHORT_SHA - else - exit 0 - fi + - '-c' + - | + if [[ "$BRANCH_NAME" == "master" ]] + then + image=$(cat /workspace/imagename) + docker push $image + else + exit 0 + fi