Azure Devops의 프로젝트에 다른 빌드가 존재하도록 트리거
A
빌드 파이프 라인으로 호출 된 리포지토리 이름이 azure-pipelines.yml
다음 B
과 같이 빌드 파이프 라인으로 호출 된 다른 리포지토리 가 있습니다.azure-pipelines.yml
모두 A
와 B
같은 프로젝트 받고있다ProjectA
이것은 흐름입니다
- repo A,
build => release (stages ops and dev)
- repo B,
Build create the Artifact and store the Artifact
그래서 내가 달성하고 싶은 것은 릴리스가 repo A에서 완료 되 자마자 빌드 repo B를 트리거해야한다는 A
것입니다 . 내 파이프 라인 은 다음과 같습니다.
name: SomethingFancy
trigger:
- none
resources:
containers:
- container: docker
image: docker:1.6
- container: python3
image: python:3
variables:
major: 2
minor: 0
그래서 파이프 라인을 B
다음과 같이 만들었습니다 .
name:
trigger:
- none
resources:
pipelines:
- pipeline: SomethingFancy
source: azure-pipelines
branch: DATA-1234
project: ProjectA
trigger:
branches:
- DATA-1234
stages:
- dev
- ops
containers:
- container: docker
image: docker:1.6
지금까지 "파이프 라인 리소스 SomethingFancy 입력이 유효해야합니다."라고 불평하므로 파이프 라인을 실행할 수 없습니다. 문서에 따라 그것은 뭔가 # identifier for the resource (used in pipeline resource variables)
입니다.
나는 자원의 수집을 위해 [this] [1]를 언급하고있다.
또한 [api] [2] 호출을 사용하여의 빌드를 대기열 B
에 추가하려고했지만 파이프 라인 분기를 추가하는 B
방법 또는 매개 변수를 전달하는 방법 과 같이 게시물 메시지의 본문을 찾을 수 없습니다. 파이프 라인에B
편집하다
첨부 된 내 파이프 라인 이름 [! [여기에 이미지 설명 입력] [3]] [3]을 참조하고 빌드 소스 파이프 라인도 호출 azurepipelines.yml
하고 릴리스 파이프 라인에는Dev
이제 내 파이프 라인 B는 다음과 같습니다.
resources:
pipelines:
- pipeline: azurepipelines
source: azurepipelines
branch: DATA-1234
project: ProjectA
trigger:
branches:
- DATA-1234
stages:
- Dev
여전히 .NET Framework의 빌드 파이프 라인이 자동으로 시작되지 않습니다 B
. [1]:https://docs.microsoft.com/en-us/azure/devops/pipelines/process/resources?view=azure-devops&tabs=example#resources-pipelines [2] : https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-5.1 [삼]: https://i.stack.imgur.com/2Uk7A.png
답변
repo A의 흐름이 build => release (stages ops and dev)
. 나는이 궁금 build
와 같은 빌드 파이프 라인이다 azure-pipelines.yml
, 그리고 release (stages ops and dev)
푸른 개발 운영 자료 허브의 고전 출시 파이프 라인입니까? 파이프 라인 리소스 트리거는 클래식 릴리스 파이프 라인에서 작동하지 않음을 알아야합니다.
build => release (stages ops and dev)
repo A의 경우 동일한 파이프 라인 (예 : azure-pipelines.yml)에 있어야합니다. 따라서 파이프 라인 B에서 정의한 파이프 라인 리소스 트리거는 파이프 라인 A가 아래와 같은 경우에만 작동합니다.
name: ..
trigger:
- none
resources:
containers:
..
variables:
..
stages:
- stage: build # build the project in build stage
jobs:
- job
..
- stage: ops #stage ops
jobs:
- job:
...
- stage: dev #stage dev
jobs:
- job:
...
source
줄리가 NG-B 바와 같이 파이프 라인에서 파이프 라인 A의 이름이다. 아래 예를 참조하십시오.
resources:
pipelines:
- pipeline: {Can be Any String} #identifier for the resource (used in pipeline resource variables)
source: {Name of the pipeline A what you see in the UI} #name of the pipeline that produces an artifact
파이프 라인 A의 이름 :

파이프 라인 B의 리소스 트리거 :
resources:
pipelines:
- pipeline: AnyString
source: pipelineA
branch: DATA-1234
저장소 A의 릴리스 파이프 라인이 클래식 릴리스 파이프 라인 인 경우. 이 외부 작업 Trigger Build in stage dev를 추가 하여 단계 dev에서 파이프 라인 B를 트리거 할 수 있습니다 .
- task: benjhuser.tfs-extensions-build-tasks.trigger-build-task.TriggerBuild@3
displayName: 'Trigger a new build of 48'
inputs:
buildDefinition: {ID of pipeline B}
buildParameters: 'variableName: variableValue'
password: '$(System.AccessToken)'
파이프 라인 A에서 파이프 라인 B로 일부 변수를 전달하려는 경우 buildParameters
필드를 사용할 수 있습니다 .
파이프 라인 B에서 변수 버튼을 클릭하여 변수 값을 보유 할 변수를 정의합니다. (참고 :이 옵션을 선택하면이 파이프 라인을 실행할 때 사용자가이 값을 재정 의하여 A 파이프 라인에서 재정의 할 수 있습니다.)
항상 Rest api를 사용하여 파이프 라인을 트리거 할 수 있습니다. 자세한 정보는 아래 스레드를 참조하십시오.
이 실
Powershell을 통해 Azure-Devops 파이프 라인 작업에 여러 매개 변수 보내기
Azure 파이프 라인에 파일을 전달할 수 있나요?
최신 정보:
Builds-Queue rest api를 사용하여 파이프 라인을 트리거 할 수 있습니다 .
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=6.1-preview.6
아래 예를 참조하십시오.
curl -X POST --silent \
-H "Authorization:Bearer $(System.AccessToken)" \
-H "Content-Type:application/json" \
$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=6.1-preview.6 \
-d '{
"definition":{ "id": id-of-pipelineB},
"sourceBranch":"refs/heads/DATA-1234"
}'
동일한 문서에서 읽은 것처럼 source
리포지토리 A의 파이프 라인 이름으로 속성을 설정해야한다고 생각합니다 .source: SomethingFancy
오류 메시지는 지정한 이름을 가진 파이프 라인을 찾을 수 없다는 것을 알려주는 것 같습니다. 아마도 name
YAML 파이프 라인의 빌드 번호 지정 형식을 참조하기 때문일 것입니다.
name: $(BuildID)
@Roderick이 언급했듯이 파이프 라인의 이름은 UI에 표시되는 이름이어야합니다. 프로젝트의 기본 "Azure Pipelines"화면에서. 먼저 "세 개의 점"을 클릭하여 하위 메뉴를 표시 한 다음 "이름 변경 / 이동"을 클릭합니다. 예시 스크린 샷 :

이제 파이프 라인 B에서 YAML을 업데이트하는 데 필요한 프로젝트 이름과 파이프 라인 이름이 있어야하며 작동해야합니다.
많은 투쟁과 현명한 사람들의 도움으로 마침내 문제를 해결할 수 있습니다. 누구나 심판을받을 수 있도록 여기에 게시하고 있습니다. 이것은 현재 작동하고 있습니다 : ListBuild 및 QueueTheBuild
name="ProjectA"
curl --silent -X GET -H "Authorization:Bearer $(System.AccessToken)" -H "Content-Type:application/json" $(System.TeamFoundationCollectionUri)/$(System.TeamProject)/_apis/build/definitions?api-version=6.0 --output /tmp/response.json #Now get the build-id of your project you are interested in #please be aware that api-version > 6 has different json output and below command #may not help you to give the right id id=$(cat /tmp/response.json | jq -r --arg key ${name} '.value[] | select(.name==$key)| .id' --raw-output)
#create your body to post
generate_post_data()
{
cat <<EOF
{
"sourceBranch":"refs/heads/DATA-1234",
"definition":{"id": $id} } EOF } #Now queue your build to run #have to still verify if this command works for API_VERSION 6 curl -X POST \ --silent \ -H "Authorization:Bearer $(System.AccessToken)" \
-H "Content-Type:application/json" \
$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=6.1-preview.6 \
--output /tmp/response1.json \
-d "$(generate_post_data)"
#check the outcome
cat /tmp/response1.json