Using the Docker orb it is possible to build and publish a Docker image to Docker Hub (or another container registry).
It seems prudent to use that image for running tests / jobs on CircleCI. I cannot figure out using a dynamically tagged image built in a workflow for subsequent workflow jobs. Is this possible? I am looking for something like:
image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:<< pipeline.git.revision >>
tag: << pipeline.git.revision >>
It is possible, but you would take the docker/publish: part of your script and place it into a job, this job’s name can then be used as the input for the ‘requires’ parameter so that ‘test’ is only scheduled after the build and push has completed.
The structure of workflows and jobs is detailed here
Thanks, but I’m not really sure still how to use. In the example syntax I’m already using the job name as a
requires to enforce this. The part I’m unsure of is how to swap images based on the pipeline git revision.
“docker/publish:” is not a job name, it is an ORB-defined command like ‘docker:’ is a system-defined command in the ‘test:’ job that you have defined in the example that you have posted.
So you need to define another job and move the ‘docker/publish’ part of your script to the new job.
I think the issue has come from the way that the ORB examples are written. As shown they work as long as you are not trying to do job-related tasks. To use a feature like ‘requires’ you need to pass it a defined job name, which is not available when you follow the example code.
docker/publish is a job that can be required:
Here’s a screenshot of it in use / PR demoing:
The issue I’m trying to solve for isn’t the workflow configuration - but the ability to use a dynamic tag for a docker image:
I’m unsure of is how to swap images based on the pipeline git revision.
My mistake (it is always good to learn something new).
What is the error message that you are getting?
One possible issue is that << pipeline.git.revision >> is being passed to the orb by reference, rather than by value. and ORBs do not have access to the name space in which pipeline parameters are placed. The result I think is a 'Unknown variable(s) error.