0

Hi I am new to AzureDevops and pipelines, I am trying to create a CmdLine Task With a script that sets some variables based on the branch name here the script :

- task: CmdLine@2
  displayName: Find Branch type
  inputs:
   script: |
     IF contains($(Build.SourceBranch), 'release')==True (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranch), 'support') (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranchName), 'develop') (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranchName), 'master') (set isLongBranch=True
      ) ELSE IF contains($(Build.SourceBranch), 'hotfix') (set isLongBranch=True
      ) ELSE (set isLongBranch=False)
     IF contains($(Build.SourceBranch), 'release') (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranch), 'support'), 'support')] (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranchName), 'develop') (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranchName), 'master') (set isSonar=False
      ) ELSE IF contains($(Build.SourceBranch), 'hotfix') (set isSonar=True
      ) ELSE IF contains($(Build.SourceBranch), 'feature') (set isSonar=True
      ) ELSE IF %isPoolRequest%==True (set isSonar=False
      ) ELSE (set isSonar=False)
      #echo $(Build.SourceBranch)
      #echo $(Build.SourceBranchName)

The error I get is :

'release')==True was unexpected. ##[error]Cmd.exe has stopped. exit code : '255'.

1
  • How about the issue? Does the answer below resolved your question, If not, would you please let me know the latest information about this issue? Commented May 11, 2021 at 8:46

1 Answer 1

0

Azure devops pipeline CmdLine Task script error

I got the same error with you, if I use the same code as you.

Generally, we use the findstr to check if the variable contains substring, like:

echo $(Build.SourceBranch) | findstr "release" >nul &&(
    echo "include"
)

Alternatively, you could use powershell scripts to do this:

$files = @("$(Build.SourceBranch)")
$excludeTypes = @("*release*","*support*", "*master*")

    foreach ($type in $excludeTypes) {
        if ($file -like $type) { 
            Write-Host ("Match found: {0} matches {1}" -f $file, $type)
            $Env:isLongBranch = true
        } 
          else
        {
          $Env:isLongBranch = False
        }
    }

You could check this thread for some more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.