print current directory in bash command inside cloud build yaml

1.7k Views Asked by At

So i want to print the current working directory after reading the git tag of the commit example :

/demo
/test
/prod

So when a tag contains verxxx-demo the inline script will know that it needs to switch to the specific folder. My problem is now that i want to print the current path after the folder is switched and usually in linux you do it with pwd but in cloudbuild seems not to work or i am missing something .

if [[ $TAG_NAME == *test* ]]
        then
          cd org/test
          echo switched "($PWD)"
        elif [[ $TAG_NAME == *demo* ]]
        then
          cd org/demo
          echo switched folder
        else
          echo no tag
        fi

when i use this code , i get the next error in cloudbuild :

Your build failed to run: generic::invalid_argument: generic::invalid_argument: invalid value for 'build.substitutions': key in the template "PWD" is not a valid built-in substitution

Any suggestions how to tackle this one ? so i can print the current path after the change folder happens ?

1

There are 1 best solutions below

0
On

I think what you want is

echo "switched `pwd`"

based on this answer.

I know the variable substitution can be tricky with cloudbuild, so please lmk if that doesn't work.