Commit de5dd327 authored by Kamil Trzciński's avatar Kamil Trzciński

Add `CI_COMMIT_BRANCH` variable

This significantly simplifies
handling between Tags/Branches/Merge Requests
and makes `workflow:rules` easy to use.
parent 2b1d47a2
......@@ -638,6 +638,7 @@ module Ci
variables.append(key: 'CI_COMMIT_BEFORE_SHA', value: before_sha)
variables.append(key: 'CI_COMMIT_REF_NAME', value: source_ref)
variables.append(key: 'CI_COMMIT_REF_SLUG', value: source_ref_slug)
variables.append(key: 'CI_COMMIT_BRANCH', value: ref) if branch?
variables.append(key: 'CI_COMMIT_TAG', value: ref) if tag?
variables.append(key: 'CI_COMMIT_MESSAGE', value: git_commit_message.to_s)
variables.append(key: 'CI_COMMIT_TITLE', value: git_commit_full_title.to_s)
......
---
title: Make `workflow:rules` to work well with Merge Requests
merge_request:
merge_request: 21742
author:
type: changed
......@@ -37,6 +37,7 @@ future GitLab releases.**
| `CI_COMMIT_REF_SLUG` | 9.0 | all | `$CI_COMMIT_REF_NAME` lowercased, shortened to 63 bytes, and with everything except `0-9` and `a-z` replaced with `-`. No leading / trailing `-`. Use in URLs, host names and domain names. |
| `CI_COMMIT_SHA` | 9.0 | all | The commit revision for which project is built |
| `CI_COMMIT_SHORT_SHA` | 11.7 | all | The first eight characters of `CI_COMMIT_SHA` |
| `CI_COMMIT_BRANCH` | 12.6 | 0.5 | The commit branch name. Present only when building branches. |
| `CI_COMMIT_TAG` | 9.0 | 0.5 | The commit tag name. Present only when building tags. |
| `CI_COMMIT_TITLE` | 10.8 | all | The title of the commit - the full first line of the message |
| `CI_CONCURRENT_ID` | all | 11.10 | Unique ID of build execution within a single executor. |
......
......@@ -2589,6 +2589,19 @@ describe Ci::Build do
it { is_expected.to include(job_variable) }
end
context 'when build is for branch' do
let(:branch_variable) do
{ key: 'CI_COMMIT_BRANCH', value: 'master', public: true, masked: false }
end
before do
build.update(tag: false)
pipeline.update(tag: false)
end
it { is_expected.to include(branch_variable) }
end
context 'when build is for tag' do
let(:tag_variable) do
{ key: 'CI_COMMIT_TAG', value: 'master', public: true, masked: false }
......
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