azure-devopsazure-pipelines

Require explicit resource input in Azure pipeline


Whan I run a pipeline without specifying an external resource in the pipeline it runs anyway with the defaults as configured in the .yml file:

resources:
  pipelines:
  - pipeline: PipelineA
    source: 'A'
    branch: master
    trigger: none
  - pipeline: PipelineB
    source: 'B'
    branch: master
    trigger: none

Is there any way I can enforce providing the resources from the azure web UI when requesting without resorting to some bogus defaults that will fail the run when not overridden?


Solution

  • Is there any way I can enforce providing the resources from the azure web UI when requesting without resorting to some bogus defaults that will fail the run when not overridden?

    Yes. I suggest that you can use Runtime Parameters to force users to input the resources version(version: buildnumber) to override the Pipeline resource default value.

    Here is an example:

    parameters:
    - name: PipelineAVersion
      type: string
    
    - name: PipelineBVersion
      type: string
    
    resources:
      pipelines:
      - pipeline: PipelineA
        source: 'A'
        branch: master
        version: ${{parameters.PipelineAVersion}}
        trigger: none
      - pipeline: PipelineB
        source: 'B'
        branch: master
        version: ${{parameters.PipelineBVersion}}
        trigger: none
    

    When we run the Pipeline, it will force user to input the Pipeline version of the resource.

    enter image description here

    If you don't provide the required version parameters, it will not run the pipeline and show the following errors:

    A value for the 'parameter' parameter must be provided.

    enter image description here

    Note: The version field in the pipeline resources needs to input the Build Number value of the pipeline.

    Refer to this doc: resources.pipelines.pipeline definition