I want to use Gitlab CI/CD for deployment. The same codebase is used to deploy to different environments and requires a statefile (state of environment) for deployment, which need to be updated after the deployment, and fetched before deployment. As it is a critical piece of information I want it to be a build artifact.
Consider my deployment pipeline and different jobs deploy-env1
and deploy-env2
. Is it possible to define the jobs in a way they
state.dat
as a build artifact (easy using the artifacts
option)As it seems I currently cannot configure a job to depend on itself, do you know if there is a way to realize this?
No there is no implemented function to handle this.
But there is a possible work around, I haven't tried this yet, and a 3rd party solution.
The workaround: You can build yourself a script which uses the Gitlab Jobs API to download the latest artifacts for your branch. Example in the Gitlab docs
Another workaround: Intstead of the downloading using the API you can also use a combination of artifacts and cache objects
The clean solution: Would be set up a artifact service which is not provided by Gitlab. You would deploy your file there and would it then retrieve again from the same service. Such programs are Artifactory and Nexus
thanks for your answer! the first solution would definitely work, even though it would need additional scripting to find the id of the latest successful job run of the same ref. good idea! The problem I see with the cache combination is that the documentation says it's not guaranteed to be available (when is it cleared?). Maybe you're right and I should have a look at the two programs you mentioned, but of course using the pre-existing Gitlab-only solution would be better.
@muffel On default caches are runner-local. And thus if you have multiple runners your cached build artifacts won't be available to all of them. For downloading, you don't need to find the actual job id, because artifacts are always overwritten - you always get the latest ones from the last successful job.