Commit 5a7e4dfd authored by Kamil Trzcinski's avatar Kamil Trzcinski

Merge branch 'after-script' into make-before-after-overridable

* after-script:
  Add CHANGELOG and documentation
  Rename finally_script to after_script

Conflicts:
	lib/ci/gitlab_ci_yaml_processor.rb
	spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
parents 4cc9a02e a0afeefd
...@@ -21,6 +21,7 @@ v 8.7.0 (unreleased) ...@@ -21,6 +21,7 @@ v 8.7.0 (unreleased)
- Make /profile/keys/new redirect to /profile/keys for back-compat. !3717 - Make /profile/keys/new redirect to /profile/keys for back-compat. !3717
- Preserve time notes/comments have been updated at when moving issue - Preserve time notes/comments have been updated at when moving issue
- Make HTTP(s) label consistent on clone bar (Stan Hu) - 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) - Expose label description in API (Mariusz Jachimowicz)
- API: Ability to update a group (Robert Schilling) - API: Ability to update a group (Robert Schilling)
- API: Ability to move issues (Robert Schilling) - API: Ability to move issues (Robert Schilling)
......
...@@ -15,6 +15,7 @@ If you want a quick introduction to GitLab CI, follow our ...@@ -15,6 +15,7 @@ If you want a quick introduction to GitLab CI, follow our
- [.gitlab-ci.yml](#gitlab-ci-yml) - [.gitlab-ci.yml](#gitlab-ci-yml)
- [image and services](#image-and-services) - [image and services](#image-and-services)
- [before_script](#before_script) - [before_script](#before_script)
- [after_script](#after_script)
- [stages](#stages) - [stages](#stages)
- [types](#types) - [types](#types)
- [variables](#variables) - [variables](#variables)
...@@ -80,6 +81,9 @@ services: ...@@ -80,6 +81,9 @@ services:
before_script: before_script:
- bundle install - bundle install
after_script:
- rm secrets
stages: stages:
- build - build
- test - test
...@@ -104,6 +108,7 @@ There are a few reserved `keywords` that **cannot** be used as job names: ...@@ -104,6 +108,7 @@ There are a few reserved `keywords` that **cannot** be used as job names:
| stages | no | Define build stages | | stages | no | Define build stages |
| types | no | Alias for `stages` | | types | no | Alias for `stages` |
| before_script | no | Define commands that run before each job's script | | 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 | | variables | no | Define build variables |
| cache | no | Define list of files that should be cached between subsequent runs | | cache | no | Define list of files that should be cached between subsequent runs |
...@@ -118,6 +123,11 @@ used for time of the build. The configuration of this feature is covered in ...@@ -118,6 +123,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 `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. 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
`stages` is used to define build stages that can be used by jobs. `stages` is used to define build stages that can be used by jobs.
......
...@@ -4,12 +4,12 @@ module Ci ...@@ -4,12 +4,12 @@ module Ci
DEFAULT_STAGES = %w(build test deploy) DEFAULT_STAGES = %w(build test deploy)
DEFAULT_STAGE = 'test' 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, ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services,
:allow_failure, :type, :stage, :when, :artifacts, :cache, :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) def initialize(config, path = nil)
@config = YAML.safe_load(config, [Symbol], [], true) @config = YAML.safe_load(config, [Symbol], [], true)
...@@ -44,7 +44,7 @@ module Ci ...@@ -44,7 +44,7 @@ module Ci
def initial_parsing def initial_parsing
@before_script = @config[:before_script] || [] @before_script = @config[:before_script] || []
@finally_script = @config[:finally_script] @after_script = @config[:after_script]
@image = @config[:image] @image = @config[:image]
@services = @config[:services] @services = @config[:services]
@stages = @config[:stages] || @config[:types] @stages = @config[:stages] || @config[:types]
...@@ -86,7 +86,7 @@ module Ci ...@@ -86,7 +86,7 @@ module Ci
artifacts: job[:artifacts], artifacts: job[:artifacts],
cache: job[:cache] || @cache, cache: job[:cache] || @cache,
dependencies: job[:dependencies], dependencies: job[:dependencies],
finally_script: job[:finally_script] || @finally_script, after_script: job[:after_script] || @after_script,
}.compact }.compact
} }
end end
...@@ -96,8 +96,8 @@ module Ci ...@@ -96,8 +96,8 @@ module Ci
raise ValidationError, "before_script should be an array of strings" raise ValidationError, "before_script should be an array of strings"
end end
unless @finally_script.nil? || validate_array_of_strings(@finally_script) unless @after_script.nil? || validate_array_of_strings(@after_script)
raise ValidationError, "finally_script should be an array of strings" raise ValidationError, "after_script should be an array of strings"
end end
unless @image.nil? || @image.is_a?(String) unless @image.nil? || @image.is_a?(String)
...@@ -173,8 +173,8 @@ module Ci ...@@ -173,8 +173,8 @@ module Ci
raise ValidationError, "#{name} job: before_script should be an array of strings" raise ValidationError, "#{name} job: before_script should be an array of strings"
end end
if job[:finally_script] && !validate_array_of_strings(job[:finally_script]) if job[:after_script] && !validate_array_of_strings(job[:after_script])
raise ValidationError, "#{name} job: finally_script should be an array of strings" raise ValidationError, "#{name} job: after_script should be an array of strings"
end end
if job[:image] && !validate_string(job[:image]) if job[:image] && !validate_string(job[:image])
......
...@@ -333,30 +333,30 @@ module Ci ...@@ -333,30 +333,30 @@ module Ci
end end
end end
describe "finally_script" do describe "after_script" do
context "in global context" do context "in global context" do
let(:config) { let(:config) {
{ {
finally_script: ["finally_script"], after_script: ["after_script"],
test: { script: ["script"] } test: { script: ["script"] }
} }
} }
it "return finally_script in options" do it "return after_script in options" do
expect(subject[:options][:finally_script]).to eq(["finally_script"]) expect(subject[:options][:after_script]).to eq(["after_script"])
end end
end end
context "overwritten in local context" do context "overwritten in local context" do
let(:config) { let(:config) {
{ {
finally_script: ["local finally_script"], after_script: ["local after_script"],
test: { finally_script: ["local finally_script"], script: ["script"] } test: { after_script: ["local after_script"], script: ["script"] }
} }
} }
it "return finally_script in options" do it "return after_script in options" do
expect(subject[:options][:finally_script]).to eq(["local finally_script"]) expect(subject[:options][:after_script]).to eq(["local after_script"])
end end
end end
end end
...@@ -689,18 +689,18 @@ EOT ...@@ -689,18 +689,18 @@ EOT
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: before_script should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: before_script should be an array of strings")
end end
it "returns errors if finally_script parameter is invalid" do it "returns errors if after_script parameter is invalid" do
config = YAML.dump({ finally_script: "bundle update", rspec: { script: "test" } }) config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) 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 end
it "returns errors if job finally_script parameter is not an array of strings" do it "returns errors if job after_script parameter is not an array of strings" do
config = YAML.dump({ rspec: { script: "test", finally_script: [10, "test"] } }) config = YAML.dump({ rspec: { script: "test", after_script: [10, "test"] } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) 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 end
it "returns errors if image parameter is invalid" do it "returns errors if image parameter is invalid" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment