Skip to content

ccsdcsdc

ccsdcsdc #33

name: PR Triggered Tests
on:
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
trigger-azure-pipeline:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.base.ref, 'develop')
steps:
- name: Check if authorized to run tests
id: check
run: |
# Add any conditions if necessary. For now, always allow.
echo "ok=true" >> $GITHUB_OUTPUT
- name: Trigger Azure DevOps Pipeline
if: steps.check.outputs.ok == 'true'
run: |
PAT="${{ secrets.AZURE_DEVOPS_PAT }}"
ORG="sergiovelderrain"
PROJECT="sergiovelderrain"
PIPELINE_ID="3"
# You can try a more recent api-version, for example "7.1-preview.1".
API_VERSION="7.1-preview.1"
if [ -z "$PAT" ]; then
echo "AZURE_DEVOPS_PAT is not set or empty!"
exit 1
fi
# Base64 encode the PAT for Basic auth
AUTH=$(echo -n ":$PAT" | base64)
# Extract the PR branch name from the event.
# For a forked PR, this is something like: <branch_name>
# We'll need to prepend refs/heads/ for Azure DevOps.
PR_HEAD_REF="${{ github.event.pull_request.head.ref }}"
# Construct the JSON payload with properly escaped quotes.
# Using double-quotes around the entire JSON and escaping internal quotes is safest.
JSON_BODY="{
\"resources\": {
\"repositories\": {
\"self\": {
\"refName\": \"refs/heads/${PR_HEAD_REF}\"
}
}
}
}"
echo "Triggering Azure DevOps pipeline with the following JSON:"
echo "$JSON_BODY"
# Use --http1.1 and -v for verbose output to help debug issues if any.
# Add --fail to ensure the command fails if we get a non-2xx response.
curl --http1.1 --fail -v -X POST \
-H "Authorization: Basic $AUTH" \
-H "Content-Type: application/json" \
-d "$JSON_BODY" \
"https://dev.azure.com/$ORG/$PROJECT/_apis/pipelines/$PIPELINE_ID/runs?api-version=$API_VERSION"