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
Jérome Perrin
gitlab-ce
Commits
1e811eb8
Commit
1e811eb8
authored
Mar 13, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new collections to define build predefined variables
parent
769f87ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
53 deletions
+50
-53
app/models/ci/build.rb
app/models/ci/build.rb
+50
-53
No files found.
app/models/ci/build.rb
View file @
1e811eb8
...
@@ -430,14 +430,14 @@ module Ci
...
@@ -430,14 +430,14 @@ module Ci
end
end
def
user_variables
def
user_variables
return
[]
if
user
.
blank?
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
return
variables
if
user
.
blank?
[
variables
.
append
(
key:
'GITLAB_USER_ID'
,
value:
user
.
id
.
to_s
)
{
key:
'GITLAB_USER_ID'
,
value:
user
.
id
.
to_s
,
public:
true
},
variables
.
append
(
key:
'GITLAB_USER_EMAIL'
,
value:
user
.
email
)
{
key:
'GITLAB_USER_EMAIL'
,
value:
user
.
email
,
public:
true
},
variables
.
append
(
key:
'GITLAB_USER_LOGIN'
,
value:
user
.
username
)
{
key:
'GITLAB_USER_LOGIN'
,
value:
user
.
username
,
public:
true
},
variables
.
append
(
key:
'GITLAB_USER_NAME'
,
value:
user
.
name
)
{
key:
'GITLAB_USER_NAME'
,
value:
user
.
name
,
public:
true
}
end
]
end
end
def
secret_variables
(
environment:
persisted_environment
)
def
secret_variables
(
environment:
persisted_environment
)
...
@@ -540,60 +540,57 @@ module Ci
...
@@ -540,60 +540,57 @@ module Ci
CI_REGISTRY_USER
=
'gitlab-ci-token'
.
freeze
CI_REGISTRY_USER
=
'gitlab-ci-token'
.
freeze
def
predefined_variables
def
predefined_variables
variables
=
[
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
{
key:
'CI'
,
value:
'true'
,
public:
true
},
variables
.
append
(
key:
'CI'
,
value:
'true'
)
{
key:
'GITLAB_CI'
,
value:
'true'
,
public:
true
},
variables
.
append
(
key:
'GITLAB_CI'
,
value:
'true'
)
{
key:
'GITLAB_FEATURES'
,
value:
project
.
namespace
.
features
.
join
(
','
),
public:
true
},
variables
.
append
(
key:
'GITLAB_FEATURES'
,
value:
project
.
namespace
.
features
.
join
(
','
))
{
key:
'CI_SERVER_NAME'
,
value:
'GitLab'
,
public:
true
},
variables
.
append
(
key:
'CI_SERVER_NAME'
,
value:
'GitLab'
)
{
key:
'CI_SERVER_VERSION'
,
value:
Gitlab
::
VERSION
,
public:
true
},
variables
.
append
(
key:
'CI_SERVER_VERSION'
,
value:
Gitlab
::
VERSION
)
{
key:
'CI_SERVER_REVISION'
,
value:
Gitlab
::
REVISION
,
public:
true
},
variables
.
append
(
key:
'CI_SERVER_REVISION'
,
value:
Gitlab
::
REVISION
)
{
key:
'CI_JOB_ID'
,
value:
id
.
to_s
,
public:
true
},
variables
.
append
(
key:
'CI_JOB_ID'
,
value:
id
.
to_s
)
{
key:
'CI_JOB_NAME'
,
value:
name
,
public:
true
},
variables
.
append
(
key:
'CI_JOB_NAME'
,
value:
name
)
{
key:
'CI_JOB_STAGE'
,
value:
stage
,
public:
true
},
variables
.
append
(
key:
'CI_JOB_STAGE'
,
value:
stage
)
{
key:
'CI_JOB_TOKEN'
,
value:
token
,
public:
false
},
variables
.
append
(
key:
'CI_JOB_TOKEN'
,
value:
token
,
public:
false
)
{
key:
'CI_COMMIT_SHA'
,
value:
sha
,
public:
true
},
variables
.
append
(
key:
'CI_COMMIT_SHA'
,
value:
sha
)
{
key:
'CI_COMMIT_REF_NAME'
,
value:
ref
,
public:
true
},
variables
.
append
(
key:
'CI_COMMIT_REF_NAME'
,
value:
ref
)
{
key:
'CI_COMMIT_REF_SLUG'
,
value:
ref_slug
,
public:
true
},
variables
.
append
(
key:
'CI_COMMIT_REF_SLUG'
,
value:
ref_slug
)
{
key:
'CI_REGISTRY_USER'
,
value:
CI_REGISTRY_USER
,
public:
true
},
variables
.
append
(
key:
'CI_REGISTRY_USER'
,
value:
CI_REGISTRY_USER
)
{
key:
'CI_REGISTRY_PASSWORD'
,
value:
token
,
public:
false
},
variables
.
append
(
key:
'CI_REGISTRY_PASSWORD'
,
value:
token
,
public:
false
)
{
key:
'CI_REPOSITORY_URL'
,
value:
repo_url
,
public:
false
}
variables
.
append
(
key:
'CI_REPOSITORY_URL'
,
value:
repo_url
,
public:
false
)
]
variables
.
append
(
key:
"CI_COMMIT_TAG"
,
value:
ref
)
if
tag?
variables
.
append
(
key:
"CI_PIPELINE_TRIGGERED"
,
value:
'true'
)
if
trigger_request
variables
<<
{
key:
"CI_COMMIT_TAG"
,
value:
ref
,
public:
true
}
if
tag?
variables
.
append
(
key:
"CI_JOB_MANUAL"
,
value:
'true'
)
if
action?
variables
<<
{
key:
"CI_PIPELINE_TRIGGERED"
,
value:
'true'
,
public:
true
}
if
trigger_request
variables
.
concat
(
legacy_variables
)
variables
<<
{
key:
"CI_JOB_MANUAL"
,
value:
'true'
,
public:
true
}
if
action?
end
variables
.
concat
(
legacy_variables
)
end
end
def
persisted_environment_variables
def
persisted_environment_variables
return
[]
unless
persisted_environment
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
return
variables
unless
persisted_environment
variables
=
persisted_environment
.
predefined_variables
# Here we're passing unexpanded environment_url for runner to expand,
variables
.
concat
(
persisted_environment
.
predefined_variables
)
# and we need to make sure that CI_ENVIRONMENT_NAME and
# CI_ENVIRONMENT_SLUG so on are available for the URL be expanded.
variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
environment_url
,
public:
true
}
if
environment_url
variables
# Here we're passing unexpanded environment_url for runner to expand,
# and we need to make sure that CI_ENVIRONMENT_NAME and
# CI_ENVIRONMENT_SLUG so on are available for the URL be expanded.
variables
.
append
(
key:
'CI_ENVIRONMENT_URL'
,
value:
environment_url
)
if
environment_url
end
end
end
def
legacy_variables
def
legacy_variables
variables
=
[
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
{
key:
'CI_BUILD_ID'
,
value:
id
.
to_s
,
public:
true
},
variables
.
append
(
key:
'CI_BUILD_ID'
,
value:
id
.
to_s
)
{
key:
'CI_BUILD_TOKEN'
,
value:
token
,
public:
false
},
variables
.
append
(
key:
'CI_BUILD_TOKEN'
,
value:
token
,
public:
false
)
{
key:
'CI_BUILD_REF'
,
value:
sha
,
public:
true
},
variables
.
append
(
key:
'CI_BUILD_REF'
,
value:
sha
)
{
key:
'CI_BUILD_BEFORE_SHA'
,
value:
before_sha
,
public:
true
},
variables
.
append
(
key:
'CI_BUILD_BEFORE_SHA'
,
value:
before_sha
)
{
key:
'CI_BUILD_REF_NAME'
,
value:
ref
,
public:
true
},
variables
.
append
(
key:
'CI_BUILD_REF_NAME'
,
value:
ref
)
{
key:
'CI_BUILD_REF_SLUG'
,
value:
ref_slug
,
public:
true
},
variables
.
append
(
key:
'CI_BUILD_REF_SLUG'
,
value:
ref_slug
)
{
key:
'CI_BUILD_NAME'
,
value:
name
,
public:
true
},
variables
.
append
(
key:
'CI_BUILD_NAME'
,
value:
name
)
{
key:
'CI_BUILD_STAGE'
,
value:
stage
,
public:
true
}
variables
.
append
(
key:
'CI_BUILD_STAGE'
,
value:
stage
)
]
variables
.
append
(
key:
"CI_BUILD_TAG"
,
value:
ref
)
if
tag?
variables
.
append
(
key:
"CI_BUILD_TRIGGERED"
,
value:
'true'
)
if
trigger_request
variables
<<
{
key:
"CI_BUILD_TAG"
,
value:
ref
,
public:
true
}
if
tag?
variables
.
append
(
key:
"CI_BUILD_MANUAL"
,
value:
'true'
)
if
action?
variables
<<
{
key:
"CI_BUILD_TRIGGERED"
,
value:
'true'
,
public:
true
}
if
trigger_request
end
variables
<<
{
key:
"CI_BUILD_MANUAL"
,
value:
'true'
,
public:
true
}
if
action?
variables
end
end
def
environment_url
def
environment_url
...
...
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