Skip to content

Update dependency com.microsoft.sqlserver:mssql-jdbc to v13 #1382

Update dependency com.microsoft.sqlserver:mssql-jdbc to v13

Update dependency com.microsoft.sqlserver:mssql-jdbc to v13 #1382

name: Renovate Jenkins Trigger
on:
pull_request:
types:
- opened
- synchronize
jobs:
build:
runs-on: ubuntu-latest
env:
# Username (currently my own one, use something else in the future)
JENKINS_USERNAME: "${{ secrets.RENOVATE_JENKINS_USERNAME }}"
# API token, generated in Jenkins, stored in GitHub
JENKINS_API_TOKEN: "${{ secrets.RENOVATE_JENKINS_API_TOKEN }}"
JENKINS_JOB_URL: "https://builds.gbif.org/job/ipt-renovate"
JENKINS_URL: "https://builds.gbif.org"
steps:
- name: Extract Branch Name
id: extract_branch
run: |
BRANCH_NAME=$(jq -r '.pull_request.head.ref' $GITHUB_EVENT_PATH)
echo "branch=$BRANCH_NAME" >> "$GITHUB_ENV"
- name: Trigger Jenkins Job
id: trigger_jenkins
run: |
BRANCH_NAME="${{ env.branch }}"
# Trigger the Jenkins job and capture the response headers
RESPONSE_HEADERS=$(curl -X POST -u "$JENKINS_USERNAME:$JENKINS_API_TOKEN" --user-agent renovate-trigger -s -I -D - "$JENKINS_JOB_URL/buildWithParameters?token=github-renovate-token&BRANCH_NAME=$BRANCH_NAME")
# Extract the queue number from the response headers
QUEUE_NUMBER=$(echo "$RESPONSE_HEADERS" | grep -i "^location:" | head -n 1 | tr -d '\r' | sed -E 's#^.*/queue/item/([0-9]+)/?#\1#')
# Check if QUEUE_NUMBER is a valid number
if ! [[ "$QUEUE_NUMBER" =~ ^[0-9]+$ ]]; then
echo "ERROR: Failed to extract a valid queue number. Got: '$QUEUE_NUMBER'"
echo "DEBUG: Full response headers:"
echo "$RESPONSE_HEADERS"
exit 1
fi
# Set QUEUE_NUMBER as an output variable
echo "queue_number=$QUEUE_NUMBER" >> "$GITHUB_ENV"
# Extract the HTTP response status code
HTTP_RESPONSE_STATUS=$(echo "$RESPONSE_HEADERS" | grep -i "HTTP/" | head -n 1 | awk '{print $2}')
echo "Jenkins job queued with queue number: $QUEUE_NUMBER"
echo "HTTP Response Status: $HTTP_RESPONSE_STATUS"
if [[ "$HTTP_RESPONSE_STATUS" -ne 201 ]]; then
echo "Failed to trigger Jenkins job. HTTP Response Code: $HTTP_RESPONSE_STATUS"
exit 1
fi
- name: Check Jenkins Job Status
id: check_jenkins_job
run: |
BRANCH_NAME="${{ env.branch }}"
# Access the queue_number output from the previous step
QUEUE_NUMBER="${{ env.queue_number }}"
while true; do
QUEUE_ITEM_STATUS=$(curl -s --user-agent renovate-trigger "$JENKINS_URL/queue/item/$QUEUE_NUMBER/api/json" | jq -r '.blocked')
# echo "DEBUG: Queue number: $QUEUE_NUMBER"
# echo "DEBUG: Jenkins status request - $JENKINS_URL/queue/item/$QUEUE_NUMBER/api/json"
# echo "DEBUG: Queue response - $(curl -s --user-agent renovate-trigger "$JENKINS_URL/queue/item/$QUEUE_NUMBER/api/json")"
# echo "DEBUG: Blocked status - $QUEUE_ITEM_STATUS"
if [[ "$QUEUE_ITEM_STATUS" == false ]]; then
# The job has left the queue, query the job's URL for its status
JOB_URL=$(curl -s --user-agent renovate-trigger "$JENKINS_URL/queue/item/$QUEUE_NUMBER/api/json" | jq -r '.executable.url')
# echo "DEBUG: job URL: $JOB_URL"
# RAW_JOB_RESPONSE=$(curl -s -L --user-agent renovate-trigger "$JOB_URL/api/json")
# echo "DEBUG: raw job response:"
# echo "$RAW_JOB_RESPONSE"
JOB_RESPONSE=$(curl -s -L --user-agent renovate-trigger "$JOB_URL/api/json" | jq -r '{ result: .result, is_building: .building }')
# echo "DEBUG: job response: $JOB_RESPONSE"
JOB_STATUS=$(echo "$JOB_RESPONSE" | jq -r '.result')
# echo "DEBUG: job status: $JOB_STATUS"
IS_JOB_BUILDING=$(echo "$JOB_RESPONSE" | jq -r '.is_building')
# echo "DEBUG: is job building: $IS_JOB_BUILDING"
echo "Job status is $JOB_RESPONSE"
if [[ "$IS_JOB_BUILDING" == false ]]; then
if [[ "$JOB_STATUS" == "FAILURE" || "$JOB_STATUS" == "UNSTABLE" ]]; then
echo "Jenkins job has failed."
echo "See more $JOB_URL"
exit 1
elif [[ "$JOB_STATUS" == "SUCCESS" ]]; then
echo "Jenkins job has succeeded."
echo "See more $JOB_URL"
exit 0
elif [[ "$JOB_STATUS" == "null" ]]; then
echo "Something went wrong, Jenkins job is in null status"
echo "See more $JOB_URL"
exit 1
else
echo "Jenkins job is in an unknown state $JOB_STATUS"
echo "See more $JOB_URL"
exit 1
fi
else
echo "Job is still running"
sleep 30 # Sleep for 30 seconds before checking again
fi
else
echo "Job is still in the queue..."
sleep 30
fi
done