nerdexam
Microsoft

GH-200 · Question #69

You are a DevOps engineer working on deployment workflows. You need to execute the deploy job only if the current branch name is feature-branch. Which code snippet will help you to implement the…

The correct answer is A. jobs. To conditionally run a job only on a specific branch, you use the if: conditional at the job level with a GitHub context expression referencing github.ref. The correct syntax is if: github.ref == 'refs/heads/feature-branch'. GitHub stores the full ref path (e.g…

Author and Maintain Workflows

Question

You are a DevOps engineer working on deployment workflows. You need to execute the deploy job only if the current branch name is feature-branch. Which code snippet will help you to implement the conditional execution of the job?

Options

  • Ajobs:
  • Bjobs:
  • Cjobs:
  • Djobs:

How the community answered

(62 responses)
  • A
    84% (52)
  • B
    10% (6)
  • C
    3% (2)
  • D
    3% (2)

Explanation

To conditionally run a job only on a specific branch, you use the if: conditional at the job level with a GitHub context expression referencing github.ref. The correct syntax is if: github.ref == 'refs/heads/feature-branch'. GitHub stores the full ref path (e.g., refs/heads/feature-branch), so the comparison must include that prefix. Alternatively, github.ref_name == 'feature-branch' can also work. The other options (B, C, D) likely contain incorrect context variable names or comparison syntax, which would cause the condition to never evaluate correctly.

Topics

#GitHub Actions#Conditional execution#Workflow jobs#Branch conditions

Community Discussion

No community discussion yet for this question.

Full GH-200 Practice