CircleCI Ideas

Share job execution between workflows

I have two workflows defined: snapshots build and releases build. The former is executed on PRs and pushes to master, the latter is quite similar, but executed on tags. Both workflows consist of two jobs, sharing the first one (compile_and_test):

snapshots:
jobs:
- compile_and_test
- build_and_push_snapshot_docker_image:
context: docker-hub
requires:
- compile_and_test

releases:
jobs:
- compile_and_test:
filters:
tags:
only: /.*/
branches:
ignore: /.*/
- build_and_push_release_docker_image:
context: docker-hub
requires:
- compile_and_test
filters:
tags:
only: /.*/

 

In most cases these two workflows won't be executed at the same time, but what if someone pushes a commit which is tagged, together with the said tag? I mean, what if somebody does this:

$ git commit -m "This commit is tagged"
$ git tag the-tag
$ git push origin master --tags


The compile_and_test job is executed twice! 

It would be great to add an option to start a job in a shared workflow, and then branch that workflow in other two workflows. Maybe merge after that? Maybe we could indicate when to branch (in this case if the commit is tagged).

  • Avatar32.5fb70cce7410889e661286fd7f1897de Guest
  • Apr 29 2019
  • New
  • Attach files
  • Admin
    Nathan Dintenfass commented
    29 Apr 05:03

    Are you trying to avoid duplicate branch/tag filters in a single workflow? Or is there another reason you can’t do this in a single workflow?

  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    29 Apr 05:50

    If the workflow is triggered because of a commit, then the CIRCLE_SHA1 variable is set, but not the CIRCLE_TAG variable. When it is triggered on a tag event, then yes is set. The thing is that when the repo is tag, I want to build the docker image tagging it with the repo tag string. I mean, if I tag in git with M.m.p-RELEASE, I want the Docker image to have that exact tag. But, if i push to master, I also want to perform the build, but the image's tag is the commit's hash.