[英]Azure CLI task doesn't work on Windows build agents
I've created an Azure DevOps task group to create a selenium container on Azure (Azure container instance) as follows: 我已经创建了一个Azure DevOps任务组,以在Azure(Azure容器实例)上创建一个硒容器,如下所示:
Script: 脚本:
ipAddress="$(az container create \
-g $(resourceGroup) \
--name temp-$(ContainerName) \
--image myregistry.azurecr.io/selenium/standalone-chrome \
--cpu 2 \
--memory 4 \
--os-type Linux \
--ports 4444 \
--vnet $(VNet)
--subnet $(Subnet)
--registry-username $(registryUsername) \
--registry-password $(registryPassword) \
--environment-variables \
NODE_MAX_SESSION=10 \
Browser=$(Browser) \
--query 'ipAddress.ip' -o tsv)"
echo "##vso[task.setvariable variable=$(SeleniumHubVariable);]http://$ipAddress:4444/wd/hub/"
This task is executed successfully when running on a Linux build agent. 在Linux构建代理上运行时,此任务已成功执行。
When I try to run it on a Windows build agent the task doesn't fail but the container is not created. 当我尝试在Windows构建代理上运行它时,任务不会失败,但是不会创建容器。 Output of the task is the following:
任务的输出如下:
F:\\Agent03\\w\\125\\s>ipAddress="$(az container create \\ 'ipAddress' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s> ipAddress =“ $(az container create \\'ipAddress'被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>-g myresourcegroup \\ '-g' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s> -g myresourcegroup \\'-g'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--name temp-1807-build-385769 \\ '--name' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-name temp-1807-build-385769 \\'--name'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--image mycontainerregistry.azurecr.io/selenium/standalone-chrome \\ '--image' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-image mycontainerregistry.azurecr.io/selenium/standalone-chrome \\'--image'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--cpu 2 \\ '--cpu' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-cpu 2 \\'--cpu'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--memory 4 \\ '--memory' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-内存4 \\'-内存'未被识别为内部或外部命令,可操作程序或批处理文件。 '--os-type' is not recognized as an internal or external command, operable program or batch file.
'--os-type'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--os-type Linux \\
F:\\ Agent03 \\ w \\ 125 \\ s>-os型Linux \\
F:\\Agent03\\w\\125\\s>--ports 4444 \\ '--ports' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-端口4444 \\'--ports'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--vnet ..... \\ '--vnet' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-vnet ..... \\'--vnet'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--subnet .... \\ '--subnet' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-子网.... \\'-子网'不被识别为内部或外部命令,可运行程序或批处理文件。
F:\\Agent03\\w\\125\\s>--registry-username myregistryusername \\ '--registry-username' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-注册用户名myregistryusername \\'-注册用户名'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>--registry-password *** \\ '--registry-password' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-注册表密码*** \\'--registry-密码'不被识别为内部或外部命令,可运行程序或批处理文件。
F:\\Agent03\\w\\125\\s>--environment-variables \\ '--environment-variables' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-environment-variables \\'--environment-variables'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>NODE_MAX_SESSION=10 \\ 'NODE_MAX_SESSION' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s> NODE_MAX_SESSION = 10 \\'NODE_MAX_SESSION'不被识别为内部或外部命令,可操作程序或批处理文件。
F:\\Agent03\\w\\125\\s>Browser=$(Browser) \\ 'Browser' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>浏览器= $(浏览器)\\'浏览器'未被识别为内部或外部命令,可运行程序或批处理文件。
F:\\Agent03\\w\\125\\s>--query 'ipAddress.ip' -o tsv)" '--query' is not recognized as an internal or external command, operable program or batch file.
F:\\ Agent03 \\ w \\ 125 \\ s>-query'ipAddress.ip'-o tsv)“'--query'不被识别为内部或外部命令,可操作程序或批处理文件。
What am I missing? 我想念什么? How can I make it work for both Windows and Linux?
如何使它在Windows和Linux上都可以使用?
I am now able to make it work with Windows agents, using 2 tasks. 现在,我可以使用2个任务使其与Windows代理一起使用。
Script: 脚本:
az container create ^
-g $(resourceGroup) ^
--name temp-$(ContainerName) ^
--image myregistry.azurecr.io/selenium/standalone-chrome ^
--cpu 2 ^
--memory 4 ^
--os-type Linux ^
--ports 4444 ^
--vnet $(VNet)
--subnet $(Subnet)
--registry-username $(registryUsername) ^
--registry-password $(registryPassword) ^
--environment-variables ^
NODE_MAX_SESSION=10 ^
Browser=$(Browser) ^
--query "ipAddress.ip" -o tsv>tmpFile-$(ContainerName).txt
Some notes: 一些注意事项:
\\
characters were replaced with ^
\\
字符被替换为^
--query 'ipAddress.ip'
) but on Windows I had to use double quotes ( --query "ipAddress.ip"
) --query 'ipAddress.ip'
)上工作正常,但在Windows上我必须使用双引号( --query "ipAddress.ip"
) $ipAddress = [IO.File]::ReadAllText("tmpFile-$(ContainerName).txt")
Write-Host "Selenium hub URL is http://$($ipAddress.Trim()):4444/wd/hub/"
Write-Host "##vso[task.setvariable variable=$(SeleniumHubVariable);]http://$($ipAddress.Trim()):4444/wd/hub/"
Unfortunately I had to create different versions of the tasks for each OS (Windows or Linux): 不幸的是,我必须为每个操作系统(Windows或Linux)创建不同版本的任务:
To run these tasks depending on the OS of the build agent you can set custom conditions: 要根据构建代理的操作系统运行这些任务,可以设置自定义条件:
So, to run a task on a Windows build agent you can set this custom condition: 因此,要在Windows构建代理上运行任务,可以设置以下自定义条件:
and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
To run it on a Linux build agent: 要在Linux构建代理上运行它:
and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
PS: Agent.OS
can be found on the build agent capabilities PS:可以在构建代理功能上找到
Agent.OS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.