无法在Azure管道上执行Shell脚本

问题描述 投票:0回答:1

我在Azure管道中添加了一个任务,该任务的目的是在远程Windows服务器上启用WinRM。

任务的定义如下:

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

我尝试了不同的变量,但仍然没有运气,问题是,由于空白而无法更改目录,我在它周围加上了双引号,但仍然无法正常工作,也许我没有使用正确的PreDefined变量?

错误消息如下:

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

看看下面的输出,不确定为什么不能执行?

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

我添加了双引号但仍然无法正常工作?

bash azure-devops azure-virtual-machine azure-pipelines-release-pipeline
1个回答
3
投票

有几个问题使我无法在Azure Release Pipeline上运行简单脚本,如下所示:

  1. 双引号应如下所示:

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

  2. 该脚本本身需要可执行权限,不确定在“代理”框中发生了什么,但是除非执行了明确的chmod,否则它将不会执行。

    sudo chmod +x temp.sh

    <<
  3. sed -i -e 's/\r$//' temp.sh
  4. 通过以上所有操作,脚本便可以执行!但是,我没有合并非交互式Azure CLI登录,这会出错并且没有配置资源。由以下内容修复:

  5. az ad sp create-for-rbac --name shuiexample --password "Password012!!"
  6. az login --service-principal -u $appID --password $password --tenant $tenant

    任何人都有更好的方法,请让我知道步骤。

© www.soinside.com 2019 - 2024. All rights reserved.