Search code examples
gitlabgitlab-cigitlab-ci-runner

How to split the variable in Gitlab pipline (.gitlab-ci.yml)


I have a branch name, for example, release-1.1.3, how I can split and extract the version by writing some logic in gitlab-ci file. Is there some method available for it?

before_script

  • export BRANCH_NAME=$CI_COMMIT_REF_NAME

    // here I want to do something to extract the version

  • export Major=BRANCH_NAME.someoperation

  • export Minor=BRANCH_NAME.someoperation
  • export PATCH=BRANCH_NAME.someoperation

any other approaches are also welcome but I required the value in a separate variable which I can pass it to other operations.

I am new to gitlab-ci and working on it, thanks in advance.


Solution

  • Just split your string

    You will find some examples here.

    How to cut a string after a specific character in unix