Trigger another build exist in project in Azure Devops

后端 未结 4 2028
暖寄归人
暖寄归人 2021-01-28 13:52

I have a repo name called A with its build pipeline as azure-pipelines.yml Then I have another repo called B with its build pipeline as

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-28 14:25

    I noticed the the flow for repo A is build => release (stages ops and dev). I wonder if the build is the build pipeline as azure-pipelines.yml, and release (stages ops and dev) is the classic release pipeline in azure devops Releases hub? You should know that pipeline resources triggers doesnot work for classic release pipeline.

    build => release (stages ops and dev) for repo A should be in the same pipeline (ie. azure-pipelines.yml). So the pipeline resources trigger you defined in pipeline B only works when the pipeline A looks like below:

    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:
        ...
    

    The source in Pipeline B is the name of the pipeline A as julie-ng mentioned. See below example:

    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
    

    Name of the pipeline A:

    Resource trigger in Pipeline B:

    resources:
     pipelines:
       - pipeline: AnyString
         source: pipelineA
         branch: DATA-1234
    

    If the release pipeline for repo A is the classic release pipeline. You can add this external task Trigger Build in stage dev to trigger pipeline B in stage dev:

    - 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)'
    

    If you want to pass some variables from Pipeline A to pipeline B. you can use the buildParameters field.

    In pipelien B, Click the Variables button to define a Variable to the hold the variable value. (Note: Check this option Let users override this value when running this pipeline, so that it can be overrode from A pipeline )

    You can always use the Rest api to trigger the pipeline. Please see below threads for more inforamtion

    this thread

    send multiple parameter to Azure-Devops pipeline job via Powershell

    Can you pass a file to an azure pipeline?

    Update:

    You can use Builds - Queue rest api To trigger a pipeline.

    POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=6.1-preview.6
    

    See below example:

    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"
        }'
    

提交回复
热议问题