I've created an Azure DevOps task group to create a selenium container on Azure (Azure container instance) as follows:
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.
When I try to run it on a Windows build agent the task doesn't fail but the container is not created. 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>-g myresourcegroup \\ '-g' 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' 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' is not recognized as an internal or external command, operable program or batch file.
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>--memory 4 \\ '--memory' is not recognized as an internal or external command, operable program or batch file. '--os-type' is not recognized as an internal or external command, operable program or batch file.
F:\\Agent03\\w\\125\\s>--os-type 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>--vnet ..... \\ '--vnet' is not recognized as an internal or external command, operable program or batch file.
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>--registry-username myregistryusername \\ '--registry-username' is not recognized as an internal or external command, operable program or batch file.
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>--environment-variables \\ '--environment-variables' 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' is not recognized as an internal or external command, operable program or batch file.
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>--query 'ipAddress.ip' -o tsv)" '--query' is not recognized as an internal or external command, operable program or batch file.
What am I missing? How can I make it work for both Windows and Linux?
I am now able to make it work with Windows agents, using 2 tasks.
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"
) $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):
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:
and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
To run it on a Linux build agent:
and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
PS: Agent.OS
can be found on the build agent capabilities
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.