# Job naming consistency, Conditional workflow or jobs

**URL:** <https://discuss.circleci.com/t/job-naming-consistency-conditional-workflow-or-jobs/43984>\
**Category:** Deployments\
**Tags:** circle-yml\
**Created:** [May 10, 2022, 8:18am UTC](https://discuss.circleci.com/t/job-naming-consistency-conditional-workflow-or-jobs/43984 "2022-05-10T08:18:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Star](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/star/32/30116_2.png) [@Star](https://discuss.circleci.com/u/Star)\
**Post date:** [May 10, 2022, 8:18am UTC](https://discuss.circleci.com/t/job-naming-consistency-conditional-workflow-or-jobs/43984/1 "2022-05-10T08:18:35Z")

</div>

0

I’m trying to achieve 2 things:

1. I’d like to have a consistent naming convention for jobs in circle ci to enforce github rules before merging to release or production branches.
2. Im trying to have it all in 1 workflow, to avoid code repitition.

Ive made a file that looks something like:

```auto
version: 2.1

orbs:
  node: circleci/node@5.0.1

parameters:
  backend-service-job:
    type: boolean
    default: false
  frontend-service-job:
    type: boolean
    default: false

commands:

  run-install:
    parameters: 
      service_name:
        type: string
        default: admin
    steps:
      - checkout
      - run:
          name: Installing dependencies
          command: |
            cd << parameters.service_name >>
            npm install
  
  run-install-tests:
    parameters:
      service_name:
        type: string
        default: admin
    steps:
      - checkout
      - run:
          name: "Installing dependencies"
          command: |
            cd << parameters.service_name >>
            npm install
      - run:
          name: Running Tests
          command: |
            cd << parameters.service_name >>
            npm run test

  build-frontend-push-docker:
    parameters:
      service_name:
        type: string
        default: admin
      web_url:
        type: string
        default: admin
      sourcemap:
        type: boolean
        default: false  
    steps:
      - checkout
      - setup_remote_docker:
          version: 19.03.13
      - run:
          name: "Setup Cloud SDK"
          command: |
            gcloud setup ...
      - run:
          name: Docker build << parameters.service_name >>
          command: |
            cd << parameters.service_name >>
            docker build -t ....
      - run: 
          name: Push << parameters.service_name >> image to gcr
          command: |
            docker push ...

  build-backend-push-docker:
    parameters:
      service_name:
        type: string
        default: admin
    steps:
      - checkout
      - setup_remote_docker:
          version: 19.03.13
      - run:
          name: "Setup Cloud SDK"
          command: |
            gcloud setup....
      - run:
          name: Docker build << parameters.service_name >>
          command: |
            docker build -t ....
      - run: 
          name: Push << parameters.service_name >> image to gcr
          command: docker push ...

jobs:
  run-install-tests:
    docker:
      - image: circleci/node:14.4
    parameters: 
      service_name:
        type: string
        default: admin
    steps:
      - run-install-tests:
          service_name: << parameters.service_name >>

  install:
    docker:
      - image: circleci/node:14.4
    parameters: 
      service_name:
        type: string
        default: admin
    steps:
      - run-install:
          service_name: << parameters.service_name >>

  build-frontend-push-docker:
    docker:
      - image: google/cloud-sdk
    parameters: # parameters are at the job level
      service_name:
        type: string
        default: admin
      web_url:
        type: string
        default: admin
      sourcemap:
        type: boolean
        default: false
    steps:
      - build-frontend-push-docker:
          service_name: << parameters.service_name >>
          web_url: << parameters.web_url >>
          sourcemap: << parameters.sourcemap >>

  build-backend-push-docker:
    docker:
      - image: google/cloud-sdk
    parameters: # parameters are at the job level
      service_name:
        type: string
        default: admin
    steps:
      - build-backend-push-docker:
          service_name: << parameters.service_name >>
workflows:
  version: 2
  backend:
    when: << pipeline.parameters.backend-service-job >>
    jobs:
      - install: 
          service_name: 'backend'
      - build-backend-push-docker: 
          service_name: 'backend'
          requires:
            - install
  go-runner:
    when: << pipeline.parameters.frontend-service-job >>
    jobs:
      - run-install-tests: 
          service_name: 'frontend'
      - build-frontend-push-docker: 
          service_name: 'frontend'
          web_url: "go-runner.com"
          sourcemap: true
          requires:
            - run-install-tests
  go-runner-2:
    when: << pipeline.parameters.frontend-service-job >>
    jobs:
      - run-install-tests: 
          service_name: 'frontend'
      - build-frontend-push-docker: 
          service_name: 'frontend'
          web_url: "go-runner-2.com"
          sourcemap: true
          requires:
            - run-install-tests

```

In github i can see the persistance for following jobs, for example

1. run-install-tests
2. install
3. build-backend-push-docker

They always stay the same, which is ideal state,

The only thing that keeps changing is the `docker-frontend-push-docker-NUMBER`

and now we are back to my first 2 quesstions.

1. How can i make sure that `docker-frontend-push-docker` name stays consistent and doesnt change?
2. Is it possible to put all in 1 workflow, rather than `go-runner` and `go-runner-2` and so on?

would appreciate any input

---

<div class="post-metadata">

**Author:** ![Star](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/star/32/30116_2.png) [@Star](https://discuss.circleci.com/u/Star)\
**Post date:** [May 10, 2022, 8:23am UTC](https://discuss.circleci.com/t/job-naming-consistency-conditional-workflow-or-jobs/43984/2 "2022-05-10T08:23:32Z")

</div>

Or a better question how could i make

```auto
go-runner:
    when: << pipeline.parameters.frontend-service-job >>
    jobs:
      - run-install-tests: 
          service_name: 'frontend'
      - build-frontend-push-docker: 
          service_name: 'frontend'
          web_url: "go-runner.com"
          sourcemap: true
          requires:
            - run-install-tests

```

How could i make it dynamic and supply web\_url depending on what branch it is on? without replicating go-runner like 5 times

---

<div class="post-metadata">

**Author:** ![Star](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/star/32/30116_2.png) [@Star](https://discuss.circleci.com/u/Star)\
**Post date:** [May 10, 2022, 8:50am UTC](https://discuss.circleci.com/t/job-naming-consistency-conditional-workflow-or-jobs/43984/3 "2022-05-10T08:50:34Z")

</div>

Im getting slightly closer to a solution,

But it forces me to replicate the “Commands” section a few times, so still hoping someone from this forum could help with clean solution.

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [May 10, 2022, 5:30pm UTC](https://discuss.circleci.com/t/job-naming-consistency-conditional-workflow-or-jobs/43984/4 "2022-05-10T17:30:52Z")

</div>

Well not cleaner, but there are 2 options

- Dynamic Configuration - This is where you generate an additional .yml file at run time and so you can just write the dynamic information into the created script and then call it.

- You separate your repo from the main build/test job - so when a change happens in the repo it can pass all the details onto the independent build/test job as parameter values. This is done by using a curl call into the API.

I’m currently using the second option as it means that I am not constantly changing the config.yml file within the main code repos - instead I work on independent repos that just contain the config.yml.

---

<div class="post-metadata">

**Author:** ![Star](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/star/32/30116_2.png) [@Star](https://discuss.circleci.com/u/Star)\
**Post date:** [May 10, 2022, 10:28pm UTC](https://discuss.circleci.com/t/job-naming-consistency-conditional-workflow-or-jobs/43984/5 "2022-05-10T22:28:57Z")

</div>

Yep I see,

I agree, they are not ideal solutions.

Would be great it just had normal if else statemets and execute jobs based on those.

Atm I see that you can have a conditional workflow, but conditional workflow executes only 1 job for the conidition.

Was hoping there would be something

```auto
workflows:
  jobs:
    run-my-workflow
        IF this and this
            params _1
            run that
       ELSE IF that and that
            params_2
            run that
       ELSE
            params_default
            default job

```

Such a bummer if its non existent
