Enrique Benito Casado
Enrique Benito Casado

Reputation: 2080

How to make docker pull images in an Azure DevOps pipeline from a file.txt?

I m trying to pull images in my pipeline in a dynamic way. I have a file call "images.txt" that contain:(cat images.txt would return)

cat images.txt
  cassadra
  python
  neo4j

the way to pull a image in azure pipeline is:

that code work but its not dynamic

steps:
   - bash: |
        y='python:3.8-slim' #I m using tha as var but would work  without that
        docker pull ${y}
    
    displayName: "Docker pull"

But when I try to do it dynamically it doesnt work anymore:

That code work im my local laptop but not in azure pipelines and in theory both should work

 #!/bin/bash
 filename='images.txt'
 n=1
 while read line; do
 # reading each line
 eval docker pull "$line"
 n=$((n+1))
 done < $filename

in Azure pipelines look like this:

   - bash: |
      #x='python:3.8-slim'
      filename='images.txt'
      n=1
      while read line; do
         echo "pulling image"
         echo ${line}
         n=$((n+1))
         docker pull ${line}
     done < $filename

but I m reciving the whole time that error: so

invalid reference format

it was my understanding that everything that worked on linux would work on Azure Pipelines(inside bash) what I am not taking into account ?

Thanks in advance Enrique

Upvotes: 0

Views: 359

Answers (1)

Hugh Lin
Hugh Lin

Reputation: 19491

How to make docker pull images in an Azure DevOps pipeline from a file.txt?

For this issue, you can consider using runtime parameter instead of reading from txt file.

Runtime parameters let you have more control over what values can be passed to a pipeline. With runtime parameters you can:

  • Supply different values to scripts and tasks at runtime
  • Control parameter types, ranges allowed, and defaults
  • Dynamically select jobs and stages with template expressions

Upvotes: 2

Related Questions