Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access artifacts from previous run of same job

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?

like image 322
muffel Avatar asked Jan 31 '18 11:01

muffel


3 Answers

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

like image 69
secustor Avatar answered Oct 21 '22 03:10

secustor


Instead of using the jobs api, you can download it directly via URL

like image 42
Vanhallen Avatar answered Oct 21 '22 05:10

Vanhallen


You should consider using Dependencies along with the Artifacts: https://docs.gitlab.com/ee/ci/yaml/#dependencies

build:
 artifacts:
  paths:
   - state.dat

deploy-env1:
 dependencies:
  - build
like image 34
Bnorus Avatar answered Oct 21 '22 04:10

Bnorus