Azure DevOps yaml 中的普通(非模板)作业支持作业间变量传递,如下所示:
jobs:
- job: A
steps:
- script: "echo ##vso[task.setvariable variable=skipsubsequent;isOutput=true]false"
name: printvar
- job: B
condition: and(succeeded(), ne(dependencies.A.outputs['printvar.skipsubsequent'], 'true'))
dependsOn: A
steps:
- script: echo hello from B
Run Code Online (Sandbox Code Playgroud)
考虑到模板不支持dependsOn语法,我如何在下面做类似的事情?我需要从第一个模板获取输出并将其作为“environmentSlice”传递给第二个模板。
- stage: Deploy
displayName: Deploy stage
jobs:
- template: build-templates/get-environment-slice.yml@templates
parameters:
configFileLocation: 'config/config.json'
- template: build-templates/node-app-deploy.yml@templates
parameters:
# Build agent VM image name
vmImageName: $(Common.BuildVmImage)
environmentPrefix: 'Dev'
environmentSlice: '-$(dependencies.GetEnvironmentSlice.outputs['getEnvironmentSlice.environmentSlice'])'
Run Code Online (Sandbox Code Playgroud)
我希望将两个模板分开的原因是第二个模板是部署模板,我希望在命名第二个模板中的环境时从第一个模板输入。即 node-app-deploy.yml(第二个模板)的初始部分是:
jobs:
- deployment: Deploy
displayName: Deploy
# Because we use the environmentSlice to name …Run Code Online (Sandbox Code Playgroud) 要求
因此,Azure DevOps 中有一些新功能允许管道触发其他管道,并在此处记录:https : //docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure- devops&tabs=yaml#pipeline-triggers-1听起来不错,除了我无法获得所需的行为。我想在同一个存储库中有 2 个管道:
管道 A 语法
resources:
pipelines:
- pipeline: database
source: database
trigger:
branches:
- develop
- release/*
# The stages filter should work, according to: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml
# However, this error occurs when specifying: /azure-pipelines.yml (Line: 8, Col: 15): Stage filters in pipeline resource database is not supported.
#stages:
#- Build
- pipeline: auth
source: auth
trigger:
branches:
- develop
- release/* …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用这个 Azure DevOps API 调用:
GET https://dev.azure.com/{organization}/_apis/projects/{projectId}?api-version=5.1
Run Code Online (Sandbox Code Playgroud)
记录在此处,以在我拥有项目 ID 时检索项目名称。请注意,管道正在尝试检索定义它的项目以外的项目的项目信息。这是在管道提供自己的项目 ID 时工作的代码:
$VstsBaseRestUrl = "$(System.TeamFoundationCollectionUri)"
$projectsUrl = "$VstsBaseRestUrl/_apis/projects/${{ parameters.project }}?api-version=5.1"
$rawResponse = Invoke-WebRequest -UseDefaultCredentials -Uri $projectsUrl -Method Get -ContentType "application/json" -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Run Code Online (Sandbox Code Playgroud)
响应返回为:
{"$id":"1","innerException":null,"message":"VS800075: The project with id 'vstfs:///Classification/TeamProject/xxxxx' does not exist, or you do not have permission to access it.","typeName":"Microsoft.TeamFoundation.Core.WebApi.ProjectDoesNotExistException, Microsoft.TeamFoundation.Core.WebApi","typeKey":"ProjectDoesNotExistException","errorCode":0,"eventId":3000}
Run Code Online (Sandbox Code Playgroud)
我使用的是正确的项目 ID,那么如何向管道授予权限以授权此调用?
注意:如果不需要,我宁愿不使用 PAT,即以某种方式将其授予构建帐户,以便 SYSTEM_ACCESSTOKEN 方法继续工作。