huserben / TfsExtensions

Extensions for TFS 2015+ such as custom Widgets (require TFS 2017) and Build Tasks
MIT License
44 stars 22 forks source link

Build trigger task in Azure Devops not getting executed for template based pipelines #248

Open vivuu1989 opened 10 months ago

vivuu1989 commented 10 months ago

I have Azure Devops pipeline A to tiger another pipeline (pipeline B in the same project). Here pipeline B has some object type parameters as below and

parameters:
  envList:
  - production
  - dr
  alertList:
  - alertnumber: 01
    alertrulename: xxxxxxxxx
    appname: xxxxxxxxxxxxxxx
    query: >
      union AppExceptions, AppRequests
      | where AppRoleName == "xxxxxx"
    alertDescription: xxxxxx
    frequencyInMinutes: 10
    timeWindowInMinutes: 10
    severity: 1
    operator: GreaterThan
    threshold: 40
    autoMitigate: true
    enabled: true
    todeploy: yes

here in each parameter "alertList", I have a flag "todeploy: yes" to decide whether the particular alert need to be triggered in a particular envt, as below and this settings working fine for pipeline B.

stages:
  - ${{ each environment in parameters.envList }}:  
    - stage: BuilD_ARM_LogAnalytic_Artifact_${{ environment }}
      jobs:
        - ${{ each alert in parameters.alertList }}:
          - ${{ if eq(alert.todeploy, 'yes') }}:
            - job: BuilD_ARM_LogAnalytic_Artifact_${{ environment }}_${{ alert.alertnumber }}
              displayName: '${{ alert.alertRuleName }}'
              condition: eq('${{ alert.todeploy }}', 'yes')  

But when I used Pipeline A to trigger the pipeline B,

 steps:
 - task: TriggerBuild@4
   inputs:
     definitionIsInCurrentTeamProject: true
     buildDefinition: 'pipelineA'
     queueBuildForUserThatTriggeredBuild: true
     ignoreSslCertificateErrors: false
     useSameSourceVersion: false
     useCustomSourceVersion: false
     useSameBranch: false
     waitForQueuedBuildsToFinish: false
     storeInEnvironmentVariable: false
     templateParameters: 'alertList: [todeploy: yes]'
     authenticationMethod: 'Personal Access Token'
     password: 'xxxxxxxxxxxxxxxxx'
     enableBuildInQueueCondition: false
     dependentOnSuccessfulBuildCondition: false
     dependentOnFailedBuildCondition: false
     checkbuildsoncurrentbranch: false
     failTaskIfConditionsAreNotFulfilled: false

The Pipeline B is not getting executed and error as below

Team Project: xxxxxxxxxxxxx
Using current Collection Url
Server URL: xxxxxxxxxxxxxxxxxxxxxxxxxx
Using following Authentication Method: Personal Access Token
Using Personal Access Token
Provided team project was guid.
Context is Build - using Build Environment Variables
Build shall be triggered for same user that triggered current build: xxxxxx
Will trigger build with following template parameters: alertList: [todeploy: yes]
Found parameter alertList with value: [todeploy: yes]
Error during request (1/5)
Error message: Error: Could not queue the build because there were validation errors or warnings.
Will wait 1 seconds before retrying request...
Error during request (2/5)
Error message: Error: Could not queue the build because there were validation errors or warnings.
Will wait 2 seconds before retrying request...
Error during request (3/5)
Error message: Error: Could not queue the build because there were validation errors or warnings.
Will wait 4 seconds before retrying request...
Error during request (4/5)
Error message: Error: Could not queue the build because there were validation errors or warnings.
Will wait 8 seconds before retrying request...
Error during request (5/5)
Error message: Error: Could not queue the build because there were validation errors or warnings.
##[debug]task result: Failed
##[error]Request failed after 5 tries - see error messages in the log

Not Sure, how to pass these parameters both envt: dr and alertList with flag (todeploy: yes) from pipelineA

huserben commented 10 months ago

Hi @vivuu1989 if I'm seeing it correctly, the alertList is an array? But you're just passing a single value in the task (templateParameters: 'alertList: [todeploy: yes]').

While I don't have experience with such a setup, my assumption would be that you need to pass the "full object" - maybe you can try this once?

Note: I'm away for the coming week and will have limited access to a computer, so my responses might be delayed.

vivuu1989 commented 10 months ago

Hi @vivuu1989 if I'm seeing it correctly, the alertList is an array? But you're just passing a single value in the task (templateParameters: 'alertList: [todeploy: yes]').

While I don't have experience with such a setup, my assumption would be that you need to pass the "full object" - maybe you can try this once?

Note: I'm away for the coming week and will have limited access to a computer, so my responses might be delayed.

@huserben In my scenario, in pipeline B I need to override this parameter only and rest of the object parameters as same . Because I need just to trigger pipeline B from pipeline A, where the pipeline B has certain conditions based on this parameter to execute, and this need to be override when executing from pipeline A.

huserben commented 10 months ago

Yep, I get that, however, I'm not sure if that's possible (in general as well as with the task itself...). So that's why I wondered whether you could specify the full object to see if it works like that (meaning the problem might be in the overwriting, not somewhere else).

If this works, we could try to dig deeper. However, I'm not sure how an override would work. An option could be to somehow get the "defaults" as part of the task and then only override what's needed and send the full object (but that seems like more work and I will not have the time to focus on this).

If it works in general (meaning it's supported by Azure Pipelines), it would be good to know what we have to send in the request. Perhaps you can try to trigger some runs manually and capture the traffic to see what is sent. It might just be finding the right format to send...