This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Branch Name and Verify JIRA ID on JIRA Board | |
on: [push] | |
jobs: | |
run-script: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run If Else Script | |
run: | | |
if [[ "${{ github.event_name }}" == "push" ]]; then | |
echo "Event was a push" | |
else | |
echo "Event was not a push" | |
fi | |
- name: Check Branch Name | |
id: check-branch | |
run: | | |
branch_name="${GITHUB_REF#refs/heads/}" | |
if [[ $branch_name =~ [A-Z]{2,5}-[0-9]+ ]]; then | |
echo "Branch name contains a JIRA ID: $branch_name" | |
echo "::set-output name=jira_id::$branch_name" | |
else | |
echo "Branch name does not contain a JIRA ID: $branch_name" | |
exit 1 | |
fi | |
- name: Verify JIRA ID on JIRA Board | |
id: verify-jira-id | |
run: | | |
jira_id="${{ steps.check-branch.outputs.jira_id }}" | |
jira_url="https://your-jira-instance.atlassian.net/rest/api/2/issue/$jira_id" | |
# Replace 'your-jira-username' and 'your-jira-api-token' with your Jira credentials | |
curl -u your-jira-username:your-jira-api-token -X GET -H "Content-Type: application/json" $jira_url | grep -q 'id' && echo "JIRA ID $jira_id exists on the JIRA board" || (echo "JIRA ID $jira_id does not exist on the JIRA board" && exit 1) |