skip to Main Content

In the below task, based on the branch, how do I specify a different value for assembleQaDebug. If the branch is qa it has to be assembleQaDebug; if develop, it has to be assembleDevelopDebug . And if prod branch, it has to be assembleProdRelease. What is the best approach doing this, if there is one. Any help is much appreciated.

- task: Gradle@3
        displayName: 'Build Task'
        continueOnError: false
        inputs:
          tasks: assembleQaDebug -PversionCode=$(Build.BuildId) -PdisablePreDex --no-daemon
          publishJUnitResults: false

2

Answers


  1. The values has to be specified in ‘variables’ section:

    variables:
      - name: tf_version
        value: latest
      - name: variablegroupname
        ${{ if eq(variables['Build.SourceBranchName'], 'develop') }}:
          value: assembleDevelopDebug
        ${{ if eq(variables['Build.SourceBranchName'], 'qa') }}:
          value: assembleQaDebug
      - name: env
        ${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
          value: prod
        ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}:
          value: develop
    

    Like this you can add your variables and depending on your stage you can replace the values.

    Login or Signup to reply.
  2. Not sure if it’s the best way to do this, but I love using variables for those kind of use cases, so check this one :

    ...
    
    
    variables:
      - name: assembleDebug
        ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/prod') }}:
          value: assembleProdRelease
        ${{ elseif eq(variables['Build.SourceBranch'], 'refs/heads/qa') }}:
          value: assembleQaDebug
        ${{ elseif eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}:
          value: assembleDevelopDebug 
        
    
    ...
    
    - task: Gradle@3
      displayName: 'Build Task'
      continueOnError: false
      inputs:
        tasks: $(assembleDebug) -PversionCode=$(Build.BuildId) -PdisablePreDex --no-daemon
        publishJUnitResults: false
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search