Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

yaml - azure devOps yml pipeline: pass Boolean value to task prisma-cloud-compute-scan@2 written in template

I want to send Boolean value to task 'prisma-cloud-compute-scan@2' written in a template file. It always gives below error. Error: The 'prisma_continue_on_error' parameter value '$(prismaContinueOnError)' is not a valid Boolean.

Main pipeline abc.yml

resources:
  repositories:
    - repository: templates
      type: git
      name: my_projects/my-build-templates
      ref: refs/heads/features/add-build-template
variables:
  name: prismaContinueOnError
  value: false
  isMainBranch: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]
    
stages:
  - stage: "Build"
    displayName: Build
    jobs:
    - template: my_build_stage/my_template.yml@templates
      parameters:
        prisma_continue_on_error: $(prismaContinueOnError)

Template my_template.yml

parameters:
- name: prisma_continue_on_error
  type: boolean
  default: false
- name: pool_name
  type: string
  default: abc_pool
jobs:
  - job: Build
    pool:
      name: ${{parameters.pool_name}}
    steps:  
    - task: prisma-cloud-compute-scan@2
      inputs:
        scanType: 'images'
        twistlockService: 'SERVICE_CONNECTIONM_NAME'
        artifact: ...
      continueOnError: ${{parameters.prisma_continue_on_error}}
question from:https://stackoverflow.com/questions/65837888/azure-devops-yml-pipeline-pass-boolean-value-to-task-prisma-cloud-compute-scan

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You mixed syntaxes here

variables:
  name: prismaContinueOnError
  value: false
  isMainBranch: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]

it should be:

variables:
  prismaContinueOnError: false
  isMainBranch: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]

But this will not solve the issue, because variables are just string. You can't have variable of type boolean. You need to pass there runtime expression which delay type evaluation:

stages:
  - stage: "Build"
    displayName: Build
    jobs:
    - template: my_build_stage/my_template.yml@templates
      parameters:
        prisma_continue_on_error: ${{ variables.prismaContinueOnError }}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...