I'm trying to have my GitLab pipeline automatically tag the master
branch but with no luck.
What I want to do
Since the project is a composer package, what I want to do is get the version number from the composer.json
file, store it in a variable, and then use this variable with git to tag the branch.
What I'm doing
Here is the pipeline job part from my .gitlab-ci.yml
:
tagging:
stage: publish
image: alpine
only:
- master
script:
- version=$(cat composer.json | grep version | grep -Eo "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")
- git tag "$(version)"
- git push --tags
The error
I can't actually tell what the problem is since no output is displayed in the GitLab job output as show in the picture below
cat composer.json
before for debugging. I think the grep command fails because the file or the patters is not found.set -xv
command before may help debugging.jq
instead ofgrep
for parsing JSON files?