1

I have added a task in Azure pipelines, the aim of task is to Enable WinRM on Remote Windows Servers.

Definition of task is below:

set -x
pwd
"cd $(System.DefaultWorkingDirectory)/_Terraform Build Phase/drop/terraform/scripts"
echo $/
sudo ./temp.sh
echo $?

I tried different variables but still no luck, the issue is, it is not able to change directory because of white space, I have double quotes around it but still not working, maybe I am not using the correct PreDefined variable?

Error message is as below:

2019-02-25T23:39:09.5826778Z ==============================================================================
2019-02-25T23:39:09.5826827Z Task         : Command Line
2019-02-25T23:39:09.5826855Z Description  : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-02-25T23:39:09.5826885Z Version      : 2.146.1
2019-02-25T23:39:09.5827075Z Author       : Microsoft Corporation
2019-02-25T23:39:09.5827104Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-02-25T23:39:09.5827131Z ==============================================================================
2019-02-25T23:39:09.7013466Z Generating script.
2019-02-25T23:39:09.7057060Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/69f83a50-dbda-4ddc-a5ac-d658cebf6030.sh
2019-02-25T23:39:09.7110679Z /home/vsts/work/r1/a
2019-02-25T23:39:09.7110949Z $/
2019-02-25T23:39:09.7115232Z + pwd
2019-02-25T23:39:09.7115916Z + 'cd /home/vsts/work/r1/a/_Terraform Build Phase/drop/terraform/scripts'
2019-02-25T23:39:09.7116546Z /home/vsts/work/_temp/69f83a50-dbda-4ddc-a5ac-d658cebf6030.sh: line 3: cd /home/vsts/work/r1/a/_Terraform Build Phase/drop/terraform/scripts: No such file or directory
2019-02-25T23:39:09.7117181Z + echo '$/'
2019-02-25T23:39:09.7117272Z + sudo ./temp.sh
2019-02-25T23:39:09.9383963Z sudo: ./temp.sh: command not found
2019-02-25T23:39:09.9385705Z + echo 1
2019-02-25T23:39:09.9387433Z 1
2019-02-25T23:39:09.9478312Z ##[section]Finishing: Enable WinRM

Have a look at the output below, not sure why it cannot excute?

2019-02-26T03:47:57.4977014Z ==============================================================================
2019-02-26T03:47:57.4977119Z Task         : Command Line
2019-02-26T03:47:57.4977157Z Description  : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-02-26T03:47:57.4977195Z Version      : 2.146.1
2019-02-26T03:47:57.4977413Z Author       : Microsoft Corporation
2019-02-26T03:47:57.4977452Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-02-26T03:47:57.4977490Z ==============================================================================
2019-02-26T03:47:57.6351017Z Generating script.
2019-02-26T03:47:57.6400544Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/d66aeba8-bdab-42b1-8988-cb139d4169a9.sh
2019-02-26T03:47:57.6466344Z /home/vsts/work/r1/a
2019-02-26T03:47:57.6466863Z $
2019-02-26T03:47:57.6474398Z + pwd
2019-02-26T03:47:57.6475184Z + cd '/home/vsts/work/r1/a/_Terraform Build Phase/drop/terraform/scripts/'
2019-02-26T03:47:57.6475966Z + echo '$'
2019-02-26T03:47:57.6476271Z + ls
2019-02-26T03:47:57.6476447Z azure_rm.py
2019-02-26T03:47:57.6476490Z InstallWinRM.sh
2019-02-26T03:47:57.6476558Z temp.sh
2019-02-26T03:47:57.6476708Z 0
2019-02-26T03:47:57.6476917Z + echo 0
2019-02-26T03:47:57.6476972Z + sudo ./temp.sh
2019-02-26T03:47:57.9981782Z sudo: ./temp.sh: command not found
2019-02-26T03:47:58.0025055Z + echo 1
2019-02-26T03:47:58.0025466Z 1
2019-02-26T03:47:58.0111749Z ##[section]Finishing: Enable WinRM

I have added double quotes but still not working?

4
  • Are you sure the path is correct? Commented Feb 26, 2019 at 3:21
  • Downloading drop/terraform/scripts/temp.sh to /home/vsts/work/r1/a/_Terraform Build Phase/drop/terraform/scripts/temp.sh Downloaded drop/terraform/scripts/temp.sh to /home/vsts/work/r1/a/_Terraform Build Phase/drop/terraform/scripts/temp.sh Commented Feb 26, 2019 at 3:41
  • I have no idea why it is not working when I am using the same path. Commented Feb 26, 2019 at 3:58
  • Your quoting is off, "cd path" tries to execute the string cd path as a command, which of course is invalid. You want cd "path" to run the command cd with the string path as its quoted argument. Voting to close as trivial typo. Commented Feb 26, 2019 at 6:12

1 Answer 1

3

There were several issues which caused me the grief from running the simple script on Azure Release Pipeline, listed as below:

  1. The double quote should have been like below:

    cd $(System.DefaultWorkingDirectory)/"_Terraform Build Phase"/drop/terraform/scripts

  2. The script itself needs executable permissions, not sure what happened on the Agent box but unless explicit chmod is done, it won't execute.

    sudo chmod +x temp.sh

  3. I did dos2unix on the script from my end, still, there were control M characters, so I had to run the below trick to overcome them, so it becomes executable:

    sed -i -e 's/\r$//' temp.sh

  4. Doing all the above allowed the script to execute! however, I didn't incorporate non-interactive Azure CLI Login, which errored out and did not provision resources. Fixed by the following:

    az ad sp create-for-rbac --name shuiexample --password "Password012!!"

    az login --service-principal -u $appID --password $password --tenant $tenant

    Anyone has better approach, steps please let me know.

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

2 Comments

Azure Devops pipelines are incredibly faulty! I am having problems running "sed" commands. They work like a charm in ANY ubuntu, but on the devops agent they don't work :(
Yes, I know. Suggest you raise a ticket in Visual Studio Community or Visual Studio Development Community

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.