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 can use YAML anchor feature to set a variable that you can use in a job scripts.
.get_version: &get_version
- "export SERVICE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')"
- "Current version is: $SERVICE_VERSION"
and then somewhere in script part:
.gitlab-ci.yml
:
variables:
CONTAINER_NAME: myService
script:
- echo "My own script"
- *get_version
- docker build --iidfile imageid.txt --cache-from $CONTAINER_NAME:$SERVICE_VERSION -t $CONTAINER_NAME:$SERVICE_VERSION .
- docker push $CONTAINER_NAME:$SERVICE_VERSION