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.