lundi 22 novembre 2021

Check existence of input value in a shell script output using if else statement

I have a list of images and their respective tags in a given images.json file, like below:

{
  "image1":"1.1",
  "image2": "1.2",
  "image3": "1.3"
}

I was able to use a sed command to read values from above images.json and store each column in an array , such as

image=${arraydata[0]}
tag=${arraydata[1]}

For each image, I would like to compare if its tag exists in the below output I get from a curl command:

curl -X GET https://docker.jfrog.io/artifactory/api/docker/docker-local/v2/$image/tags/list?

Output of above:

{
  "name" : "image1",
  "tags" : [ "1.1", "1.2" ]
}{
  "name" : "image2",
  "tags" : [ "1.1", "1.2", "1.3" ]
}{
  "name" : "image3",
  "tags" : [ "1.1", "1.2", "1.4" ]
}

I would like to have an if/else statement to check if tag for an image exists in the results above:

  • If exists then do nothing
  • Else do docker push jfrog/$image:$tag

Aucun commentaire:

Enregistrer un commentaire