microsoft / azure-pipelines-yaml

Azure Pipelines YAML examples, templates, and community interaction
MIT License
1.19k stars 923 forks source link

Parameter or variable of type object or list that can be set from a script #567

Open anilsamuel opened 2 years ago

anilsamuel commented 2 years ago

Hooping to do something similar but looking for a way to set the list value of parameters.StackNames using command below prior to Delete ${{ stack }}

aws cloudformation describe-stacks --query "[].StackName)"

parameters:
- name: stackNames
  type: object

steps:
- ${{ each stack in parameters.stackNames }}:
  - task: AmazonWebServices.aws-vsts-tools.AWSShellScript.AWSShellScript@1
      displayName: Delete ${{ stack }}
      inputs:
        awsCredentials: ${{ parameters.awsCredentials }}
        regionName: $(region)
        scriptType: inline
        inlineScript: |
           aws cloudformation delete-stack --stack-name ${{ stack }}
           aws cloudformation wait stack-delete-complete --stack-name ${{ stack }}
jadzdtc commented 2 years ago

Dude, what you are asking for is not an Azure Devops issue, it is rather groundbreaking feature request.

AFAIK template expansion (notation ${{ }} ) works only with parameters and preassigned variables, i.e. you cannot achieve template expansion upon runtime values. You may of course start another pipeline, passing parameter obtained in runtime, but I suppose it is not what you ultimately wanted to achieve.

anilsamuel commented 2 years ago

Dude, what you are asking for is not an Azure Devops issue, it is rather groundbreaking feature request.

AFAIK template expansion (notation ${{ }} ) works only with parameters and preassigned variables, i.e. you cannot achieve template expansion upon runtime values. You may of course start another pipeline, passing parameter obtained in runtime, but I suppose it is not what you ultimately wanted to achieve.

Could you please provide snippet that use another pipeline to achieve this ? as i do not understand how.

cedrox commented 1 year ago

You can have a pipeline that calculate something and trigger a new one from the parent with this pws command 👍 # Run the pipeline $pipelineQueue = Invoke-Expression "az pipelines run --commit-id $($using:commitId) --id $($using:pipelineId) --branch $($using:branch) --parameters $($processedParams) | ConvertFrom-Json" $buildID = $pipelineQueue.id

Also parameters can be problematic if you plan to use complex object.

CurlyBytes commented 1 year ago

Why is this not working, i got similar doing like this suppose you have this steps image

then you should supply it in the parameters as object too image so when calling or trigger the pipeline, you can still use the yaml by extending it

image

CurlyBytes commented 1 year ago

@anilsamuel thats how i did it by calling the parameter object and set on the script , here is also another from blog https://igeorgiev.eu/devops/azure-pipelines-use-each-loop/