sh 检查Azure DevOps Service Connect是否可访问

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 检查Azure DevOps Service Connect是否可访问相关的知识,希望对你有一定的参考价值。

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'

#!/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

以上是关于sh 检查Azure DevOps Service Connect是否可访问的主要内容,如果未能解决你的问题,请参考以下文章

如何将Azure DevOps中的代码发布到Azure App Service中

Azure DevOps 中的 Service Fabric 生成的输出不正确

使用 Azure DevOps 部署具有不同名称的 Service Fabric 服务

Azure Devops 无法连接到 Service Fabric 群集

Service Fabric、Azure Devops 部署失败:指定的网络密码不正确

通过Azure DevOps部署Service Fabric并在Octopus中管理环境变量