Need to build multiple docker images

Hey I have requirement where I have a git mono repo with multiple Dockerfiles. So I want to build docker images when there are changes to Dockerfiles in the git repo. For a single Dockerfile I was able to build. I was unable to do If there are two Dockerfiles that I need to build dynamically by fetching modified docker files in git repo and pass them to build steps.

Is there any way that I can loop the build step in my freestyle step for multiple Dockerfiles?.
Does Codefresh support for loop through a step?.

Here is my yaml

  check_image:
    title: check for modified Docker file
    image: quay.io/codefreshplugins/alpine:3.8
    commands:
      -  apk add --no-cache git
      -  git --no-pager diff --name-only master >>modifiedFiles.txt
      -  >- 
        while IFS="" read -r p || [ -n "$p" ]
         do 
           cf_export SUB_DIR=`echo $p | cut -d / -f 1`
           echo $SUB_DIR 
           printf '%s\n' "$p" 
         done < modifiedFiles.txt  
    stage: "check_image"
    
  build:
    title: "Building Docker image"
    type: "build"
    image_name: "image-${{SUB_DIR}}"
    tag: 'latest'
    working_directory: ${{main_clone}}/${{SUB_DIR}}
    dockerfile: "Dockerfile"
    no_cache: true
    no_cf_cache: true
    stage: "build"
    disable_push: true

My git repo is like.

folder1/Dockerfile
folder2/Dockerfile

Hello and welcome to the Codefresh community.

No, we don’t support loops. However we do support monorepo triggers.

Use a restriction field such as **/Dockerfile* and launch a pipeline that builds a single dockerfile.

If you really want loops you need to write a custom step. Here is an example that loops over a set of git repos and clones them one by one.

Hello Team,

Thanks for the response. I can trigger the pipeline by restrictions. But I want to build the multiple Dockerfiles dynamically by looping as I don’t know which Dockerfile I was going to build. I will try that. Thanks for the support.

Another option to explore is to create different triggers for you mono repo (1 for each subfolder).
Then associate VARIABLES to each trigger that would point to each subfolder and use those to select the correct sub-directory, image name to build, …

We use a similar approach to build our typed steps (GitHub - codefresh-io/steps).
So for the ServiceNow plugin,
for example, I have a trigger looking for changes in

incubating/service-now/**

I have the following variables (under Advanced options)
Codefresh___steps_-_all-steps

And we use those variables in our build step:

  BuildImage:
    title: Building Docker Image
    type: build
    working_directory: "./steps/${{STAGE}}/${{STEP_NAME}}"
    dockerfile: "Dockerfile"
    image_name: codefreshplugins/${{IMAGE_NAME}}

That way each plugin is built individually, only when something changes in its subfolder without the need for complex looping mechanism to detect changes.
the downside is that you need to explicitly add trigger manually (it can also be done with the CLI if you have a bunch of them to do at once)

it seems my variables screenshot does not want to show: so I have 3 variables defined on my trigger:

  • IMAGE_NAME: service-now
  • STAGE: incubating
  • STEP_NAME: service-now

STEP_NAME and IMAGE_NAME are simply in case somebody does not follow the standard of naming the image and typed-step the same way