Skip to content
Snippets Groups Projects
Commit 43604cdd authored by Kamil Trzcińśki's avatar Kamil Trzcińśki
Browse files

Merge branch 'make-before-after-overridable' into pass-before-script-to-runner

* make-before-after-overridable:
  Update CHANGELOG and add documentation
  Add CHANGELOG and documentation
  Rename finally_script to after_script

Conflicts:
	lib/ci/gitlab_ci_yaml_processor.rb
parents 6e60be56 38b15e35
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -21,6 +21,7 @@ v 8.7.0 (unreleased)
- Make /profile/keys/new redirect to /profile/keys for back-compat. !3717
- Preserve time notes/comments have been updated at when moving issue
- Make HTTP(s) label consistent on clone bar (Stan Hu)
- Add support for `after_script`, requires Runner 1.2 (Kamil Trzciński)
- Expose label description in API (Mariusz Jachimowicz)
- API: Ability to update a group (Robert Schilling)
- API: Ability to move issues (Robert Schilling)
Loading
Loading
@@ -45,6 +46,7 @@ v 8.7.0 (unreleased)
- Use rugged to change HEAD in Project#change_head (P.S.V.R)
- API: Ability to filter milestones by state `active` and `closed` (Robert Schilling)
- API: Fix milestone filtering by `iid` (Robert Schilling)
- Make before_script and after_script overridable on per-job (Kamil Trzciński)
- API: Delete notes of issues, snippets, and merge requests (Robert Schilling)
- Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.)
- Better errors handling when creating milestones inside groups
Loading
Loading
Loading
Loading
@@ -15,6 +15,7 @@ If you want a quick introduction to GitLab CI, follow our
- [.gitlab-ci.yml](#gitlab-ci-yml)
- [image and services](#image-and-services)
- [before_script](#before_script)
- [after_script](#after_script)
- [stages](#stages)
- [types](#types)
- [variables](#variables)
Loading
Loading
@@ -29,6 +30,7 @@ If you want a quick introduction to GitLab CI, follow our
- [artifacts](#artifacts)
- [artifacts:name](#artifacts-name)
- [dependencies](#dependencies)
- [before_script and after_script](#before_script-and-after_script)
- [Hidden jobs](#hidden-jobs)
- [Special YAML features](#special-yaml-features)
- [Anchors](#anchors)
Loading
Loading
@@ -80,6 +82,9 @@ services:
before_script:
- bundle install
 
after_script:
- rm secrets
stages:
- build
- test
Loading
Loading
@@ -104,6 +109,7 @@ There are a few reserved `keywords` that **cannot** be used as job names:
| stages | no | Define build stages |
| types | no | Alias for `stages` |
| before_script | no | Define commands that run before each job's script |
| after_script | no | Define commands that run after each job's script |
| variables | no | Define build variables |
| cache | no | Define list of files that should be cached between subsequent runs |
 
Loading
Loading
@@ -118,6 +124,11 @@ used for time of the build. The configuration of this feature is covered in
`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.
 
### after_script
`after_script` is used to define the command that will be run after for all
builds. This has to be an array or a multi-line string.
### stages
 
`stages` is used to define build stages that can be used by jobs.
Loading
Loading
@@ -332,6 +343,8 @@ job_name:
| dependencies | no | Define other builds that a build depends on so that you can pass artifacts between them|
| artifacts | no | Define list build artifacts |
| cache | no | Define list of files that should be cached between subsequent runs |
| before_script | no | Override a set of commands that are executed before build |
| after_script | no | Override a set of commands that are executed after build |
 
### script
 
Loading
Loading
@@ -676,6 +689,23 @@ deploy:
script: make deploy
```
 
### before_script and after_script
It's possible to overwrite globally defined `before_script` and `after_script`:
```yaml
before_script
- global before script
job:
before_script:
- execute this instead of global before script
script:
- my command
after_script:
- execute this after my script
```
## Hidden jobs
 
>**Note:**
Loading
Loading
Loading
Loading
@@ -4,12 +4,12 @@ module Ci
 
DEFAULT_STAGES = %w(build test deploy)
DEFAULT_STAGE = 'test'
ALLOWED_YAML_KEYS = [:before_script, :finally_script, :image, :services, :types, :stages, :variables, :cache]
ALLOWED_YAML_KEYS = [:before_script, :after_script, :image, :services, :types, :stages, :variables, :cache]
ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services,
:allow_failure, :type, :stage, :when, :artifacts, :cache,
:dependencies, :before_script, :finally_script]
:dependencies, :before_script, :after_script]
 
attr_reader :before_script, :finally_script, :image, :services, :variables, :path, :cache
attr_reader :before_script, :after_script, :image, :services, :variables, :path, :cache
 
def initialize(config, path = nil)
@config = YAML.safe_load(config, [Symbol], [], true)
Loading
Loading
@@ -44,7 +44,7 @@ module Ci
 
def initial_parsing
@before_script = @config[:before_script]
@finally_script = @config[:finally_script]
@after_script = @config[:after_script]
@image = @config[:image]
@services = @config[:services]
@stages = @config[:stages] || @config[:types]
Loading
Loading
@@ -87,7 +87,7 @@ module Ci
dependencies: job[:dependencies],
before_script: job[:before_script] || @before_script,
script: [job[:script]].flatten,
finally_script: job[:finally_script] || @finally_script,
after_script: job[:after_script] || @after_script,
}.compact
}
end
Loading
Loading
@@ -97,8 +97,8 @@ module Ci
raise ValidationError, "before_script should be an array of strings"
end
 
unless @finally_script.nil? || validate_array_of_strings(@finally_script)
raise ValidationError, "finally_script should be an array of strings"
unless @after_script.nil? || validate_array_of_strings(@after_script)
raise ValidationError, "after_script should be an array of strings"
end
 
unless @image.nil? || @image.is_a?(String)
Loading
Loading
@@ -174,8 +174,8 @@ module Ci
raise ValidationError, "#{name} job: before_script should be an array of strings"
end
 
if job[:finally_script] && !validate_array_of_strings(job[:finally_script])
raise ValidationError, "#{name} job: finally_script should be an array of strings"
if job[:after_script] && !validate_array_of_strings(job[:after_script])
raise ValidationError, "#{name} job: after_script should be an array of strings"
end
 
if job[:image] && !validate_string(job[:image])
Loading
Loading
Loading
Loading
@@ -335,30 +335,30 @@ module Ci
end
end
 
describe "finally_script" do
describe "after_script" do
context "in global context" do
let(:config) {
{
finally_script: ["finally_script"],
after_script: ["after_script"],
test: { script: ["script"] }
}
}
 
it "return finally_script in options" do
expect(subject[:options][:finally_script]).to eq(["finally_script"])
it "return after_script in options" do
expect(subject[:options][:after_script]).to eq(["after_script"])
end
end
 
context "overwritten in local context" do
let(:config) {
{
finally_script: ["local finally_script"],
test: { finally_script: ["local finally_script"], script: ["script"] }
after_script: ["local after_script"],
test: { after_script: ["local after_script"], script: ["script"] }
}
}
 
it "return finally_script in options" do
expect(subject[:options][:finally_script]).to eq(["local finally_script"])
it "return after_script in options" do
expect(subject[:options][:after_script]).to eq(["local after_script"])
end
end
end
Loading
Loading
@@ -697,18 +697,18 @@ EOT
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: before_script should be an array of strings")
end
 
it "returns errors if finally_script parameter is invalid" do
config = YAML.dump({ finally_script: "bundle update", rspec: { script: "test" } })
it "returns errors if after_script parameter is invalid" do
config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "finally_script should be an array of strings")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "after_script should be an array of strings")
end
 
it "returns errors if job finally_script parameter is not an array of strings" do
config = YAML.dump({ rspec: { script: "test", finally_script: [10, "test"] } })
it "returns errors if job after_script parameter is not an array of strings" do
config = YAML.dump({ rspec: { script: "test", after_script: [10, "test"] } })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: finally_script should be an array of strings")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: after_script should be an array of strings")
end
 
it "returns errors if image parameter is invalid" do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment