带有Docker的Jenkins Active Choices参数获得Azure标记 [英] Jenkins Active Choices Parameter with Docker to get Azure tags
问题描述
对于部署作业,我想设置一个Jenkins作业,该作业从特定的Azure存储库接收所有现有标签,并使其在Active Choices参数中可供选择.
For deployment jobs, I want to set up a Jenkins job which receives all existing tags from a specific Azure repository and makes them available for selection in an Active Choices parameter.
我尝试了几件事,但没有任何效果.在下面的代码中,您可以看到我尝试使用的最后一个代码.我想拉一个其中包含我们的Azure CLI和配置的Docker容器,此后,我要访问该容器并启动一个Azure命令(该代码尚不在代码中,因为在此步骤之前失败).我得到的错误是:
I tried several things but nothing has worked. In the code below you can see the last code with which I tried. I want to pull a Docker container which has our Azure CLI and our config in it, after that I want to access the container and start an Azure command (which is not in the code yet, as it fails prior to this step). The Error I get is:
groovy.lang.MissingMethodException:方法Script1.sh()的签名不适用于参数类型:(Java.lang.String)值:"docker login -u ...等等"
groovy.lang.MissingMethodException: No signature of method Script1.sh() is applicable for argument types: (Java.lang.String) values: "docker login -u... and so on"
def dockerImage = 'ourRegistry/deploy/azure'
def output = []
try {
sh 'docker login -u="our_robot_user" -p="TOKEN" ourRegistry && docker pull ${dockerImage}'
dockerRun = docker.image(dockerImage).withRun('--env-file=azure.env')
dockerRun.inside("-u user") {
output.push("INSIDE")
//res = sh(returnStdout: true, script: 'az acr repository show-tags --name xx --subscription "xx" --repository "xx"')
//output.push(res)
}
} catch (error) {
output.push(error)
}
return output
是否甚至可以在Active Choices参数中运行它?还是可以导入特定的库来使它正常工作?还是有更好的方法?
Is it even possible to run this in an Active Choices parameter? Or can I import specific libraries to get this working? Or is there a better way?
推荐答案
我已经成功复制了完整的方案(即设置Jenkins作业以从特定的Azure容器注册表存储库中接收所有现有标签的要求,按照下面提到的过程,使它们可供选择,以作为我们在构建作业时的参数.)
I have successfully reproduced the complete scenario (i.e., the requirement of 'setting up a Jenkins job which receives all the existing tags from a specific Azure Container Registry repository and make them available for selection as parameters while we build the job') by following the below mentioned process.
仅供参考,这是通过使用选择参数"来实现的,如下面的屏幕截图所示.
Just FYI this is achieved by using "choice parameter" as shown in below screenshot.
以下Jenkins管道脚本正常工作的先决条件是
Pre-requisites for the below Jenkins pipeline script to work are