Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/run/ci_provider/gitlab_ci/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ impl TryFrom<&Config> for GitLabCIProvider {
let repository = get_env_variable("CI_PROJECT_NAME")?;

let ci_pipeline_source = get_env_variable("CI_PIPELINE_SOURCE")?;

let branch_name = get_env_variable("CI_COMMIT_REF_NAME")?;
let branch_ref = format!("refs/heads/{branch_name}");

// compute the branch or tag ref which mimics GitHub behavior
// CI_COMMIT_TAG is only present in pipelines for tags.
// See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
let branch_or_tag_ref = get_env_variable("CI_COMMIT_TAG")
.map(|tag_name| format!("refs/tags/{tag_name}"))
.unwrap_or(format!("refs/heads/{branch_name}"));

// https://docs.gitlab.com/ee/ci/jobs/job_rules.html#ci_pipeline_source-predefined-variable
let (event, ref_, base_ref, head_ref) = match ci_pipeline_source.as_str() {
Expand Down Expand Up @@ -72,15 +79,20 @@ impl TryFrom<&Config> for GitLabCIProvider {
}

// For pipelines triggered by a Git push event, including for branches and tags.
"push" => (RunEvent::Push, branch_ref, Some(branch_name), None),
"push" => (RunEvent::Push, branch_or_tag_ref, Some(branch_name), None),

// For scheduled pipelines.
"schedule" => (RunEvent::Schedule, branch_ref, Some(branch_name), None),
"schedule" => (
RunEvent::Schedule,
branch_or_tag_ref,
Some(branch_name),
None,
),

// For pipelines created by using a trigger token or created via the GitLab UI.
"trigger" | "web" => (
// For pipelines created with the api, using a trigger token or via the GitLab UI.
"trigger" | "web" | "api" => (
RunEvent::WorkflowDispatch,
branch_ref,
branch_or_tag_ref,
Some(branch_name),
None,
),
Expand Down