Last active
February 20, 2019 12:45
-
-
Save cicorias/554b40a108f2008b1a6dccc4dd1b0f82 to your computer and use it in GitHub Desktop.
check if an Azure DevOps Service Connect is accessible
This file contains hidden or 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
| resources: | |
| - repo: self | |
| trigger: | |
| branches: | |
| include: | |
| - master | |
| # variables: | |
| # container_registry: 'agogosacrdemo.azurecr.io/' | |
| # service_endpoint_guid: $AGO_AZURE_SUBSCRIPTION_ENDPOINT | |
| # acccess_token: $SYSTEM_ACCESSTOKEN | |
| jobs: | |
| - job: Phase_1 | |
| displayName: Agogosml-Build-CI | |
| condition: succeeded() | |
| steps: | |
| - bash: | | |
| env | |
| displayName: 'dump the env' | |
| - task: ShellScript@2 | |
| env: | |
| SYSTEM_ACCESSTOKEN: $(System.AccessToken) | |
| inputs: | |
| scriptPath: ./private.sh | |
| displayName: 'Get service endpoint information' | |
| - bash: | | |
| JQ_INSTALLED="$(command -v jq)" | |
| if [ -z "$JQ_INSTALLED" ]; then | |
| echo "JQ not installed - exiting" | |
| exit 1 | |
| else | |
| echo "JQ installed at - ${JQ_INSTALLED}" | |
| fi | |
| displayName: 'check if jq is installed' | |
| - bash: | | |
| if [ -z "$AGO_AZURE_SUBSCRIPTION_ENDPOINT" ]; then | |
| echo "AGO_AZURE_SUBSCRIPTION_ENDPOINT not set - exiting" | |
| exit 1 | |
| else | |
| echo "AGO_AZURE_SUBSCRIPTION_ENDPOINT - ${AGO_AZURE_SUBSCRIPTION_ENDPOINT}" | |
| fi | |
| displayName: 'echo the service endpoint information' | |
| - bash: | | |
| env | |
| displayName: 'dump the env' | |
| - bash: echo This is a script that could use $SYSTEM_ACCESSTOKEN | |
| env: | |
| SYSTEM_ACCESSTOKEN: $(System.AccessToken) | |
| displayName: 'set token' | |
| - bash: echo ${SYSTEM_ACCESSTOKEN} | |
| env: | |
| SYSTEM_ACCESSTOKEN: $(System.AccessToken) | |
| displayName: 'echo token' | |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| endpointId="66631332-2be3-46e4-b217-0c59776cc935" | |
| echo "calling DevOps REST API" | |
| body=$(curl --request GET \ | |
| --url $SYSTEM_TEAMFOUNDATIONCOLLECTIONURI/$SYSTEM_TEAMPROJECT/_apis/serviceendpoint/endpoints/$endpointId?api-version=5.0-preview.2 \ | |
| --header "Authorization: Bearer ${SYSTEM_ACCESSTOKEN}" \ | |
| --header 'cache-control: no-cache') | |
| echo $body | |
| echo "parsing json" | |
| result=$(echo $body | jq ". | select( .id | test(\"^${endpointId}$\"; \"i\")) ") | |
| echo "checking result" | |
| if [ -z "$result" ]; then | |
| echo 'not found' | |
| exit 1 | |
| else | |
| echo $result | |
| exit 0 | |
| fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment