Home > database >  Output Variable in Maven Task Azure Pipeline
Output Variable in Maven Task Azure Pipeline

Time:01-11

I have a maven task in azure pipeline in which I want to get an output variable with value as VAR: ${{ contains($(Build.ArtifactStagingDirectory)/*.jar, 'SNAPSHOT')}} so that I can use this variable once this task is over successfully, in another task in same job and same stage. If I am trying to use set variable property with script it gives me error stating "Unexpected property script" as below:

- task: Maven@4
  displayName: 'XYZ'
  inputs:
  .
  . 
  .
  script:

What is the correct method of setting variable in maven task? Or how can we get the output of a task in azure pipeline?

CodePudding user response:

Firstly, contain or containvalue is expression of condition. You are supposed not to get the judge value 'true or false' directly through VAR: ${{ containsValue($(Build.ArtifactStagingDirectory)/.jar, 'SNAPSHOT')}} or contains($(Build.ArtifactStagingDirectory)/.jar, 'SNAPSHOT')

If you directly set a variable VAR0 with the value '$(Build.ArtifactStagingDirectory)/.jar', you will get output as 'D:\a\1\a/TestResultsTests/.jar'. You could list the files under $(Build.ArtifactStagingDirectory) but couldn't output the value of judge it with other string or values.

If you want to use maven task to generate and push files like '.jar' to $(Build.ArtifactStagingDirectory) and compare whether the file names contain 'SNAPSHOT', then maybe you cannot because we cannot get the whole path of the '$(Build.ArtifactStagingDirectory)/.jar'.

And for your reference, if you want to compare the variable var1 value generate from a previous task, you could use a powershell task to see the value:

steps:
- powershell: |
   echo "hello world"
  displayName: 'PowerShell Script'
  condition: containsValue(variables.var1, '123')

Since it will skip if the value is false and run if the value is true, you could try to use succeed or failed conditions in following tasks and set variables to corresponding value then output the variables value.

  • Related