Can't see results of cat command in container

11/3/2019

I am writing a brigade.js script to login into azure kubernetes cluster and then fetching tags of an image from acr (azure container registry). Code for doing that looks like the following:

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();

So I pulled the same image manually (microsoft/azure-cli) and tried the same commands

`${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

It shows the output, which is 0.0.4 in this case. But I get no output when I am doing the same with brigade.js

-- Vishal Tewatia
azure
azure-kubernetes
containers
ubuntu

1 Answer

11/4/2019

According to the description of your requirements, what you want is to get the last one from the tags which meet your pattern.

Firstly, you need to know the output of the command az acr repository show-tags -n nxvishal --repository tests | grep -E '\b[0-9]\.[0-9]\.[0-9]' -o. With the test, I think you need to discard the parameter -o. So the result will like this:

enter image description here

Then you can tail the last one, but it will contain a comma behand.

Finally, the whole command here:

az acr repository show-tags -n nxvishal --repository tests | grep -E '\b[0-9]\.[0-9]\.[0-9]' | tail -1
-- Charles Xu
Source: StackOverflow