1

I'm new to Azure Devops and yaml.

We have a CI/CD process running that deploys to Salesforce. As long as the deployment runs completely, the script interprets this as a success, even if the deployment returns an error result.

Current setup:

- script: |
        if [ $(setvarStep.PullRequest) = 'true' ]
            then
                echo 'DevOps Message -- Validation in Progress - Non Feature branch behavior'
                npx sfdx force:source:deploy  --checkonly --testlevel $(setvarStep.SalesforceTestLevel) --sourcepath $(salesforce.sourcepath) --targetusername $(salesforce.connectedApp.Alias)
        fi

What I'd like to do is capture the result in a variable and check for an error message in the result, and throw an error in the script, however, everytime I try to check for the error, the if block returns "no error found"

- script: |
        if [ $(setvarStep.PullRequest) = 'true' ]
            then
                echo 'DevOps Message -- Validation in Progress - Non Feature branch behavior'
                sfdxresult=$(npx sfdx force:source:deploy  --checkonly --testlevel $(setvarStep.SalesforceTestLevel) --sourcepath $(salesforce.sourcepath) --targetusername $(salesforce.connectedApp.Alias)) 


       if ($sfdxresult-like "*Component Failures*")
           then
               echo "found the error!"
           else 
               echo "no error found!"
            fi
        fi            

Any advice?

aj2taylo
  • 11
  • 1
  • Did you try to print the $sfdxresult? First see if the expected output is shown. – massie Dec 24 '19 at 10:29
  • @massie yes, I've printed out $sfdxresult (I removed my debugging for succinctness) and see the full deployment result, including the "Component Failures" string I'm checking for – aj2taylo Dec 24 '19 at 10:43
  • https://stackoverflow.com/questions/4467735/how-to-find-substring-inside-a-string-or-how-to-grep-a-variable this should be the solution – 4c74356b41 Dec 24 '19 at 10:49
  • Thank you, that was it! – aj2taylo Dec 24 '19 at 14:17

0 Answers0