CI: self-defined env-vars for artifacts
Description
gitlab-ci exports the CI_BUILD_REF
environment variable, which is the full hash of the last commit.
sometimes this is a bit too verbose, and one would like to use something shorter (the abbreviated hash; or the output of a command like git describe --tag
).
This can actually be done (though it is undocumented!) , e.g. like in the following .gitlab-ci.yml
:
build:
script:
- declare -x MYVAR=$(git describe --tags)
- make VERSION="${MYVAR}"
unfortunately the so-defined variables are not exported for building artifacts
.
E.g. the following will create an artifact named myproject-.zip
(note the missing version)
artifacts:
name: myproject-${MYVAR}
Here's another use-case, that uses make install
to create artifacts, in a way that prevents any name-clashes:
build:
stage: build
- declare -x TMPDIR=$(mktemp -d -p.)
- make install DESTDIR=${TMPDIR}
artifacts:
paths:
- ${TMPDIR}
Proposal
Provide a way to create dynamic variables that can be used in all stages of the CI-process.
Edited by umlaeute