Change build id to reflect both "build" and "job"
I would like to have an identifier that is common across all jobs of a build but unique across builds.
I'm building a docker container and I wish to use such an identifier in my various stages.
Pseudo .gitlab-cy.yml
stages: [ build, test, deploy ]
build:
script:
- make
- docker build -t my-docker-image:$CI_BUILD_ID
- docker push my-docker-image:$CI_BUILD_ID
test:
script:
- docker exec my-docker-image:$CI_BUILD_ID run-the-tests.sh
deploy:
script:
- docker push my-docker-image:$CI_BUILD_ID
The problem is that the CI_BUILD_ID isn't actually a build id, it is per job. The "build" stage will get id X, the test stage job will get Y and the deploy stage job will get Z. I was first thinking I could do Y-1 to get X but I don't think it's deterministic so if there are many build happening in parallel I could end up with the wrong number.
How can I get an identifier that is common across all jobs/stages of a build but that is unique between different builds?
Travis-CI uses N.K where N is the build and K is the job. So if the job is 123 I would get 123.1, 123.2 and 123.3 for the jobs of that build.