Microsoft

GH-200 practice question 11

GitHub Actions · free question 11 of 20

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?
  • A. jobs: deploy: if: github.ref_name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 Correct
  • B. jobs: deploy: if: github.branch.name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
  • C. jobs: deploy: if: github.ref.name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
  • D. jobs: deploy: if: github.branch_name == 'feature-branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3

Explanation

github.ref_name is the short name of the branch or tag that triggered the run, for example feature-branch, so comparing it in the job-level if condition works. github.ref is a string such as refs/heads/feature-branch, so it has no name property. The github context has no branch or branch_name property, so options B and D are not valid.

Practice the whole free set

Answer all 20 free GH-200 questions with instant feedback, or unlock all 106 questions with Learn and Exam modes.