In gitlab-ci.yml documentation, it says that
before_script is used to define the command that should be run before all jobs, including deploy jobs, but after the restoration of artifacts.
This tells me that artifact is produced before a job start running
But the artifact documentation says that
Artifacts is a list of files and directories which are attached to a job after it completes successfully
This tells me that artifact is produced after a job finish running.
This is a contradiction. Can someone please explain how this is not a contradiction?
I imagine they are talking about the artifact in previous job? But I don't know how artifact and job work and can be wrong.
Artifacts are files created as part of a build process that often contain metadata about that build's jobs like test results, security scans, etc. These can be used for reports that are displayed directly in GitLab or can be published to GitLab Pages or in some other way for users to review.
These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.
before_script is used to define the command that should be run before all builds, including deploy builds. This can be an array or a multi-line string.
The artifacts are stored by default in /home/git/gitlab/shared/artifacts . Save the file and restart GitLab for the changes to take effect.
Artifacts can be produced by build jobs from one stage and consumed by build jobs from the next stage. So before_script is run after the artifacts produced by the previous stage are restored for the current stage.
So the follwing .gitlab-ci.yml
stages:
- build
- test
before_script:
- echo "before_script"
- ls
build_artifacts:
stage: build
tags:
- docker
script:
- echo "build_artifacts"
- touch build_output
artifacts:
paths:
- build_output
test_artifacts:
stage: test
tags:
- docker
script:
- echo "test_artifacts"
Will give the following outputs:
# build_artifacts job
$ echo "before_script"
before_script
$ ls
README.md
$ echo "build_artifacts"
build_artifacts
$ touch build_output
Uploading artifacts...
build_output: found 1 matching files
Uploading artifacts to coordinator... ok id=56026 responseStatus=201 Created token=xxxxzzzz
Job succeeded
# test_artifacts job
Downloading artifacts for build_artifacts (56026)...
Downloading artifacts from coordinator... ok id=56026 responseStatus=200 OK token=xxxxzzzz
$ echo "before_script"
before_script
$ ls
README.md
build_output
$ echo "test_artifacts"
test_artifacts
Job succeeded
As you can see the test_artifacts job downloads the artifacts before the before_script
runs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With