Merge branch 'issue_21825' into 'master'
Add information about user and manual build start to runner as variables Closes #21825 See merge request !6201
This commit is contained in:
commit
c0d99638ca
|
@ -112,6 +112,7 @@ v 8.12.0 (unreleased)
|
|||
- Avoid conflict with admin labels when importing GitHub labels
|
||||
- User can edit closed MR with deleted fork (Katarzyna Kobierska Ula Budziszewska) !5496
|
||||
- Fix repository page ui issues
|
||||
- Add information about user and manual build start to runner as variables !6201 (Sergey Gnuskov)
|
||||
- Fixed invisible scroll controls on build page on iPhone
|
||||
- Fix error on raw build trace download for old builds stored in database !4822
|
||||
- Refactor the triggers page and documentation !6217
|
||||
|
|
|
@ -148,6 +148,7 @@ module Ci
|
|||
variables += runner.predefined_variables if runner
|
||||
variables += project.container_registry_variables
|
||||
variables += yaml_variables
|
||||
variables += user_variables
|
||||
variables += project.secret_variables
|
||||
variables += trigger_request.user_variables if trigger_request
|
||||
variables
|
||||
|
@ -434,6 +435,15 @@ module Ci
|
|||
read_attribute(:yaml_variables) || build_attributes_from_config[:yaml_variables] || []
|
||||
end
|
||||
|
||||
def user_variables
|
||||
return [] if user.blank?
|
||||
|
||||
[
|
||||
{ key: 'GITLAB_USER_ID', value: user.id.to_s, public: true },
|
||||
{ key: 'GITLAB_USER_EMAIL', value: user.email, public: true }
|
||||
]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_artifacts_size
|
||||
|
@ -469,6 +479,7 @@ module Ci
|
|||
]
|
||||
variables << { key: 'CI_BUILD_TAG', value: ref, public: true } if tag?
|
||||
variables << { key: 'CI_BUILD_TRIGGERED', value: 'true', public: true } if trigger_request
|
||||
variables << { key: 'CI_BUILD_MANUAL', value: 'true', public: true } if manual?
|
||||
variables
|
||||
end
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ The `API_TOKEN` will take the Secure Variable value: `SECURE`.
|
|||
| **CI_BUILD_REF_NAME** | all | all | The branch or tag name for which project is built |
|
||||
| **CI_BUILD_REPO** | all | all | The URL to clone the Git repository |
|
||||
| **CI_BUILD_TRIGGERED** | all | 0.5 | The flag to indicate that build was [triggered] |
|
||||
| **CI_BUILD_MANUAL** | 8.12 | all | The flag to indicate that build was manually started |
|
||||
| **CI_BUILD_TOKEN** | all | 1.2 | Token used for authenticating with the GitLab Container Registry |
|
||||
| **CI_PIPELINE_ID** | 8.10 | 0.5 | The unique id of the current pipeline that GitLab CI uses internally |
|
||||
| **CI_PROJECT_ID** | all | all | The unique id of the current project that GitLab CI uses internally |
|
||||
|
@ -47,6 +48,8 @@ The `API_TOKEN` will take the Secure Variable value: `SECURE`.
|
|||
| **CI_RUNNER_ID** | 8.10 | 0.5 | The unique id of runner being used |
|
||||
| **CI_RUNNER_DESCRIPTION** | 8.10 | 0.5 | The description of the runner as saved in GitLab |
|
||||
| **CI_RUNNER_TAGS** | 8.10 | 0.5 | The defined runner tags |
|
||||
| **GITLAB_USER_ID** | 8.12 | all | The id of the user who started the build |
|
||||
| **GITLAB_USER_EMAIL** | 8.12 | all | The email of the user who started the build |
|
||||
|
||||
**Some of the variables are only available when using runner with at least defined version.**
|
||||
|
||||
|
@ -60,6 +63,7 @@ export CI_BUILD_REPO="https://gitab-ci-token:abcde-1234ABCD5678ef@gitlab.com/git
|
|||
export CI_BUILD_TAG="1.0.0"
|
||||
export CI_BUILD_NAME="spec:other"
|
||||
export CI_BUILD_STAGE="test"
|
||||
export CI_BUILD_MANUAL="true"
|
||||
export CI_BUILD_TRIGGERED="true"
|
||||
export CI_BUILD_TOKEN="abcde-1234ABCD5678ef"
|
||||
export CI_PIPELINE_ID="1000"
|
||||
|
@ -78,6 +82,8 @@ export CI_SERVER="yes"
|
|||
export CI_SERVER_NAME="GitLab"
|
||||
export CI_SERVER_REVISION="70606bf"
|
||||
export CI_SERVER_VERSION="8.9.0"
|
||||
export GITLAB_USER_ID="42"
|
||||
export GITLAB_USER_EMAIL="alexzander@sporer.com"
|
||||
```
|
||||
|
||||
### YAML-defined variables
|
||||
|
|
|
@ -231,6 +231,34 @@ describe Ci::Build, models: true do
|
|||
it { is_expected.to eq(predefined_variables) }
|
||||
end
|
||||
|
||||
context 'when build has user' do
|
||||
let(:user) { create(:user, username: 'starter') }
|
||||
let(:user_variables) do
|
||||
[
|
||||
{ key: 'GITLAB_USER_ID', value: user.id.to_s, public: true },
|
||||
{ key: 'GITLAB_USER_EMAIL', value: user.email, public: true }
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
build.update_attributes(user: user)
|
||||
end
|
||||
|
||||
it { user_variables.each { |v| is_expected.to include(v) } }
|
||||
end
|
||||
|
||||
context 'when build started manually' do
|
||||
before do
|
||||
build.update_attributes(when: :manual)
|
||||
end
|
||||
|
||||
let(:manual_variable) do
|
||||
{ key: 'CI_BUILD_MANUAL', value: 'true', public: true }
|
||||
end
|
||||
|
||||
it { is_expected.to include(manual_variable) }
|
||||
end
|
||||
|
||||
context 'when build is for tag' do
|
||||
let(:tag_variable) do
|
||||
{ key: 'CI_BUILD_TAG', value: 'master', public: true }
|
||||
|
|
Loading…
Reference in New Issue