Warm tip: This article is reproduced from serverfault.com, please click

Access artifacts from previous run of same job

发布于 2018-01-31 11:19:16

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

  • add the file state.dat as a build artifact (easy using the artifacts option)
  • start with the latest version of the statefile (last successful run of same job on the current branch)
  • start with an empty file if no previous successful run is present

As it seems I currently cannot configure a job to depend on itself, do you know if there is a way to realize this?

Questioner
muffel
Viewed
11
secustor 2018-02-01 09:17:43

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