Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
a032c296
Commit
a032c296
authored
Feb 28, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move pipeline-level variables from build to pipeline
parent
1d27bf92
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
36 deletions
+46
-36
app/models/ci/build.rb
app/models/ci/build.rb
+1
-15
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+21
-3
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+2
-18
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+22
-0
No files found.
app/models/ci/build.rb
View file @
a032c296
...
...
@@ -35,6 +35,7 @@ module Ci
serialize
:yaml_variables
,
Gitlab
::
Serializer
::
Ci
::
Variables
# rubocop:disable Cop/ActiveRecordSerialize
delegate
:name
,
to: :project
,
prefix:
true
delegate
:ref_slug
,
to: :pipeline
validates
:coverage
,
numericality:
true
,
allow_blank:
true
validates
:ref
,
presence:
true
...
...
@@ -233,17 +234,6 @@ module Ci
user
==
current_user
end
# A slugified version of the build ref, suitable for inclusion in URLs and
# domain names. Rules:
#
# * Lowercased
# * Anything not matching [a-z0-9-] is replaced with a -
# * Maximum length is 63 bytes
# * First/Last Character is not a hyphen
def
ref_slug
Gitlab
::
Utils
.
slugify
(
ref
.
to_s
)
end
# Variables whose value does not depend on environment
def
simple_variables
variables
(
environment:
nil
)
...
...
@@ -541,15 +531,11 @@ module Ci
{
key:
'CI_JOB_NAME'
,
value:
name
,
public:
true
},
{
key:
'CI_JOB_STAGE'
,
value:
stage
,
public:
true
},
{
key:
'CI_JOB_TOKEN'
,
value:
token
,
public:
false
},
{
key:
'CI_COMMIT_SHA'
,
value:
sha
,
public:
true
},
{
key:
'CI_COMMIT_REF_NAME'
,
value:
ref
,
public:
true
},
{
key:
'CI_COMMIT_REF_SLUG'
,
value:
ref_slug
,
public:
true
},
{
key:
'CI_REGISTRY_USER'
,
value:
CI_REGISTRY_USER
,
public:
true
},
{
key:
'CI_REGISTRY_PASSWORD'
,
value:
token
,
public:
false
},
{
key:
'CI_REPOSITORY_URL'
,
value:
repo_url
,
public:
false
}
]
variables
<<
{
key:
"CI_COMMIT_TAG"
,
value:
ref
,
public:
true
}
if
tag?
variables
<<
{
key:
"CI_PIPELINE_TRIGGERED"
,
value:
'true'
,
public:
true
}
if
trigger_request
variables
<<
{
key:
"CI_JOB_MANUAL"
,
value:
'true'
,
public:
true
}
if
action?
variables
.
concat
(
legacy_variables
)
...
...
app/models/ci/pipeline.rb
View file @
a032c296
...
...
@@ -473,7 +473,7 @@ module Ci
end
def
predefined_variables
p
ipeline_p
redefined
=
[
predefined
=
[
{
key:
'CI'
,
value:
'true'
,
public:
true
},
{
key:
'GITLAB_CI'
,
value:
'true'
,
public:
true
},
{
key:
'CI_SERVER_NAME'
,
value:
'GitLab'
,
public:
true
},
...
...
@@ -481,10 +481,16 @@ module Ci
{
key:
'CI_SERVER_REVISION'
,
value:
Gitlab
::
REVISION
,
public:
true
},
{
key:
'CI_PIPELINE_ID'
,
value:
id
.
to_s
,
public:
true
},
{
key:
'CI_CONFIG_PATH'
,
value:
ci_yaml_file_path
,
public:
true
},
{
key:
'CI_PIPELINE_SOURCE'
,
value:
source
.
to_s
,
public:
true
}
{
key:
'CI_PIPELINE_SOURCE'
,
value:
source
.
to_s
,
public:
true
},
{
key:
'CI_COMMIT_SHA'
,
value:
sha
,
public:
true
},
{
key:
'CI_COMMIT_REF_NAME'
,
value:
ref
,
public:
true
},
{
key:
'CI_COMMIT_REF_SLUG'
,
value:
ref_slug
,
public:
true
}
]
Array
(
project
.
predefined_variables
)
+
pipeline_predefined
predefined
.
push
(
key:
'CI_COMMIT_TAG'
,
value:
ref
,
public:
true
)
if
tag?
predefined
.
push
(
key:
'CI_PIPELINE_TRIGGERED'
,
value:
'true'
,
public:
true
)
if
variables
.
any?
Array
(
project
.
predefined_variables
)
+
predefined
end
def
priority_variables
...
...
@@ -533,6 +539,18 @@ module Ci
@latest_builds_with_artifacts
||=
builds
.
latest
.
with_artifacts
.
to_a
end
# A slugified version of the ref, suitable for inclusion in URLs and
# domain names. Rules:
#
# * Lowercased
# * Anything not matching [a-z0-9-] is replaced with a -
# * Maximum length is 63 bytes
# * First/Last Character is not a hyphen
#
def
ref_slug
Gitlab
::
Utils
.
slugify
(
ref
.
to_s
)
end
private
def
ci_yaml_from_repo
...
...
spec/models/ci/build_spec.rb
View file @
a032c296
...
...
@@ -1245,24 +1245,8 @@ describe Ci::Build do
end
describe
'#ref_slug'
do
{
'master'
=>
'master'
,
'1-foo'
=>
'1-foo'
,
'fix/1-foo'
=>
'fix-1-foo'
,
'fix-1-foo'
=>
'fix-1-foo'
,
'a'
*
63
=>
'a'
*
63
,
'a'
*
64
=>
'a'
*
63
,
'FOO'
=>
'foo'
,
'-'
+
'a'
*
61
+
'-'
=>
'a'
*
61
,
'-'
+
'a'
*
62
+
'-'
=>
'a'
*
62
,
'-'
+
'a'
*
63
+
'-'
=>
'a'
*
62
,
'a'
*
62
+
' '
=>
'a'
*
62
}.
each
do
|
ref
,
slug
|
it
"transforms
#{
ref
}
to
#{
slug
}
"
do
build
.
ref
=
ref
expect
(
build
.
ref_slug
).
to
eq
(
slug
)
end
it
'delegates ref_slug method to the pipeline'
do
expect
(
build
).
to
delegate_method
(
:ref_slug
).
to
(
:pipeline
)
end
end
...
...
spec/models/ci/pipeline_spec.rb
View file @
a032c296
...
...
@@ -1280,6 +1280,28 @@ describe Ci::Pipeline, :mailer do
end
end
describe
'#ref_slug'
do
{
'master'
=>
'master'
,
'1-foo'
=>
'1-foo'
,
'fix/1-foo'
=>
'fix-1-foo'
,
'fix-1-foo'
=>
'fix-1-foo'
,
'a'
*
63
=>
'a'
*
63
,
'a'
*
64
=>
'a'
*
63
,
'FOO'
=>
'foo'
,
'-'
+
'a'
*
61
+
'-'
=>
'a'
*
61
,
'-'
+
'a'
*
62
+
'-'
=>
'a'
*
62
,
'-'
+
'a'
*
63
+
'-'
=>
'a'
*
62
,
'a'
*
62
+
' '
=>
'a'
*
62
}.
each
do
|
ref
,
slug
|
it
"transforms
#{
ref
}
to
#{
slug
}
"
do
pipeline
.
ref
=
ref
expect
(
pipeline
.
ref_slug
).
to
eq
(
slug
)
end
end
end
describe
'#execute_hooks'
do
let!
(
:build_a
)
{
create_build
(
'a'
,
0
)
}
let!
(
:build_b
)
{
create_build
(
'b'
,
0
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment