gitlab-ci.yml, before_script 和神器
gitlab-ci.yml, before_script and artifact
在gitlab-ci.yml documentation中说
before_script is used to define the command that should be run before all
jobs, including deploy jobs, but after the restoration of artifacts.
这告诉我工件是在作业开始之前生成的 运行
Artifacts is a list of files and directories which are attached to a
job after it completes successfully
这告诉我工件是在作业完成后生成的 运行。
这是矛盾的。谁能解释一下这怎么不矛盾?
我猜他们是在谈论上一份工作中的神器?但我不知道神器和工作是如何工作的,并且可能是错误的。
工件可以由一个阶段的构建作业生成,并由下一阶段的构建作业使用。因此 before_script 是 运行 在为当前阶段恢复前一阶段产生的工件之后。
所以下面的.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"
将给出以下输出:
# 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
如您所见,test_artifacts 作业在 before_script
运行 之前下载工件。
在gitlab-ci.yml documentation中说
before_script is used to define the command that should be run before all jobs, including deploy jobs, but after the restoration of artifacts.
这告诉我工件是在作业开始之前生成的 运行
Artifacts is a list of files and directories which are attached to a job after it completes successfully
这告诉我工件是在作业完成后生成的 运行。
这是矛盾的。谁能解释一下这怎么不矛盾?
我猜他们是在谈论上一份工作中的神器?但我不知道神器和工作是如何工作的,并且可能是错误的。
工件可以由一个阶段的构建作业生成,并由下一阶段的构建作业使用。因此 before_script 是 运行 在为当前阶段恢复前一阶段产生的工件之后。
所以下面的.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"
将给出以下输出:
# 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
如您所见,test_artifacts 作业在 before_script
运行 之前下载工件。