I\'m using gitLab CI for my nodejs application. In my YML file I need to call a script to build a docker image. But instead of using latest
I need to use the curren
You might not be able to do this purely in the gitlab.yml
unfortunately, you could create a shell script as follows and check this into your source control
#!/bin/sh
args=("$@")
CI_REGISTRY_IMAGE=${args[0]}
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
CONTAINER_RELEASE_IMAGE=$CI_REGISTRY_IMAGE\:$PACKAGE_VERSION
cd /opt/core/bundle && docker build -t $CONTAINER_RELEASE_IMAGE .
docker push $CONTAINER_RELEASE_IMAGE
Then execute this script with the argument of $CI_REGISTRY_IMAGE
in gitlab.yml
# ...
build:
stage: build
script:
# ...
- chmod +x script.sh
- ./script.sh $CI_REGISTRY_IMAGE
To the best of my knowledge this should work for you.
Thank you to DarrenN and dbaba on Github for his package.json version extract shell function