azureazure-pipelinescicd

azure script variable not recognized


Here is my azure pipeline snippet:

- steps 
   - script : | 

         isChanged = git diff --stat abc.txt

git diff --stat abc.txt working fine. But getting isChanged is unrecognized as internal or external command


Solution

  • its not Linux(Bash) based shell, so got that error.

    Here is the correct one. default Windows shell (cmd):

    steps:
      - script: |
          REM Check if abc.txt has any changes and capture the output in a variable
          for /f "delims=" %%i in ('git diff --stat abc.txt') do set "isChanged=%%i"
    
          REM If there are no changes, set the pipeline variable isChanged to 'false', otherwise 'true'
          if "%isChanged%"=="" (
            echo No changes in abc.txt
            echo ##vso[task.setvariable variable=isChanged]false
          ) else (
            echo Changes detected in abc.txt
            echo ##vso[task.setvariable variable=isChanged]true
          )
        displayName: 'Check if abc.txt has changed'