在容器中看不到cat命令的结果

时间:2019-11-03 16:57:36

标签: azure ubuntu containers azure-kubernetes

我正在编写一个brigade.js脚本以登录到Azure kubernetes集群,然后从acr(azure容器注册表)中获取图像的标签。 这样做的代码如下所示:


var job = new Job("fetch-tag", "microsoft/azure-cli") // pulling img -> microsoft/azure-cli
    job.storage.enabled = true // enables a shared storage b/w different jobs
    job.tasks = [ // list of tasks to be performed or rather the commands to run in the pulled image
      `az login --service-principal -u ${project.secrets.azure_client_id} -p ${project.secrets.azure_client_secret} --tenant ${project.secrets.azure_tenant_id} 2>&1`, // logging into auzre kubernetes cluster
      `az acr repository show-tags -n nxvishal --repository tests | grep -E '\b[0-9]\.[0-9]\.[0-9]' -o | tail -1 > /mnt/brigade/share/image_version.txt`, // pulling the tags of tests repo, applying some regex to fiter out unwanted tags and use tail to get one tag from last
      "cat /mnt/brigade/share/image_version.txt 2>&1", // here comes the problem, it doesn't show any output
      "az account show" // shows if i logged in correctly ( and yes i get output for this which is my details which shows I am logged in and code has reached till here) 
    ]
job.run();

所以我手动拉出相同的图像(microsoft / azure-cli)并尝试了相同的命令

`${project.secrets.azure_client_id} -p ${project.secrets.azure_client_secret} --tenant ${project.secrets.azure_tenant_id} 2>&1`, // I didn't forgot to replace the secrets with appropriate string
`az acr repository show-tags -n nxvishal --repository tests | grep -E '\b[0-9]\.[0-9]\.[0-9]' -o | tail -1

它显示输出,在这种情况下为0.0.4。但是,当我与brigade.js进行相同操作时,我没有任何输出

1 个答案:

答案 0 :(得分:0)

根据需求的描述,您想要的是从符合您的模式的标签中获取最后一个。

首先,您需要了解命令(a.merge(b, on='key', how='left', indicator=True) .query('_merge == "left_only"') .drop('_merge', 1)) 的输出。通过测试,我认为您需要放弃参数az acr repository show-tags -n nxvishal --repository tests | grep -E '\b[0-9]\.[0-9]\.[0-9]' -o。因此结果将如下所示:

enter image description here

然后您可以拖尾最后一个,但是它将包含一个逗号分隔符。

最后,整个命令在这里:

-o