Semantic release with google cloud CI/CD using git annotation tag

743 views Asked by At

I am releasing the artifact to the Artifact registry in the Google cloud. I want to have a semantic versioning release cycle using the git annotation tag to the master branch.

steps:
  # This step show the version of Gradle
  - id: Gradle Install
    name: gradle:7.4.2-jdk17-alpine
    entrypoint: gradle
    args: ["--version"]

  # This step build the gradle application
  - id: Build
    name: gradle:7.4.2-jdk17-alpine
    entrypoint: gradle
    args: ["assemble"]

  - id: Publish
    name: gradle:7.4.2-jdk17-alpine
    entrypoint: "sh"
    args:
      - -c
      - |
        if [ $BRANCH_NAME == 'master' ]
        then
          echo "Branch is = $BRANCH_NAME"
          gradle publish
        fi

In the last publish step, I want to write a condition for finding the latest git tag for versioning like 1.0.0, and should run that step on only when that condition matched. Similar to the other auto tools

Now on TRAVIS CI/CD

skip_cleanup: true
on:
    all_branches: false
    branch: master
    tag: true
    condition: "$TRAVIS_TAG = ~^v\d+\.\d+\.\d+$"

What is the equivalent of the above semantic versioning release in GCP. How to write the regular expression condition on google cloud build

1

There are 1 answers

0
Robert G On

Cloud Build doesn't have semantic versioning as it doesn't include a sequential build number that increments depending on the number of commits. Substituting variable values would be the nearest equivalent for semantic versioning as there is an option for users have the option to define their own substitutions.

Here's a sample yaml file for user-defined substitution:

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build',
         '--build-arg',
         'node_version=${_NODE_VERSION_1}',
         '-t',
         'gcr.io/$PROJECT_ID/build-substitutions-nodejs-${_NODE_VERSION_1}',
         '.']
- name: 'gcr.io/cloud-builders/docker'
  args: ['build',
         '--build-arg',
         'node_version=${_NODE_VERSION_2}',
         '-t',
         'gcr.io/$PROJECT_ID/build-substitutions-nodejs-${_NODE_VERSION_2}',
         '.']
substitutions:
    _NODE_VERSION_1: v6.9.1 # default value
    _NODE_VERSION_2: v6.9.2 # default value
images: [
    'gcr.io/$PROJECT_ID/build-substitutions-nodejs-${_NODE_VERSION_1}',
    'gcr.io/$PROJECT_ID/build-substitutions-nodejs-${_NODE_VERSION_2}'
]

You can check the links below for additional information on substitutions for Cloud Build:

Let me know if you have questions or clarifications.