Manaul approval for the job with only one workflow

We are using CircleCI for our open source project. We have only one workflow is our circleci configuration for build and executing test cases. We wanted to have an approval based trigger for CircleCI but it is available only for configs with multiple workflows. Like this

workflows:
  version: 2
  build-test-and-approval-deploy:
    jobs:
      - build  # your custom job from your config, that builds your code
      - test1: # your custom job; runs test suite 1
          requires: # test1 will not run until the `build` job is completed.
            - build
      - test2: # another custom job; runs test suite 2,
          requires: # test2 is dependent on the succes of job `test1`
            - test1
      - hold: # <<< A job that will require manual approval in the CircleCI web application.
          type: approval # <<< This key-value pair will set your workflow to a status of "On Hold"
          requires: # We only run the "hold" job when test2 has succeeded
           - test2
      # On approval of the `hold` job, any successive job that requires the `hold` job will run. 
      # In this case, a user is manually triggering the deploy job.
      - deploy:
          requires:
            - hold

Since I have only one workflow like this

version: 2.1
jobs:
build:
working_directory: ~/project
docker:
- image: circleci/node:12
steps:
- checkout
- run: npm install

How can I have an approval based trigger only if I have one workflow?

Hi Harsha,

I would still suggest using the workflow syntax even for a single job. This way, you’d be able to use the type: approval property on your single build job.

Your full configuration might look something like the following:

version: 2.1
jobs:
  build:
    working_directory: ~/project
    docker:
      - image: circleci/node:12
    steps:
      - checkout
      - run: npm install

workflows:
  version: 2

  build-workflow:
    jobs:
      - build:
          type: approval

Hope this helps.

Thank you @muhammed-sayadi, the above configuration worked for getting approval for single build job. But after the approval I don’t see the build workflow getting triggered.
Below is the config file.

version: 2.1
jobs:
build:
working_directory: ~/project
docker:
- image: circleci/node:12
steps:
- checkout
- run: npm install

  - run:
      name: Publish to NPM
      command: |
        if [ -z $CIRCLE_PR_NUMBER ]; then 
          npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
          npm publish ~/project 
        else
          echo "Nothing to publish!" 
        fi

workflows:
version: 2
build-workflow:
jobs:
- build:
type: approval

And this is the link for CircleCI trigger for that particular PR

Here in the image if you see there are steps being executed after the approval.

Indeed! I just replicated the behavior you’re experiencing.
I’m not sure if this is the expected behavior. Someone from Circle would be better positioned to comment on this.

In the meantime, what I would do is add an additional job to hold the workflow and make the build job dependant on it. While not ideal, this does work.

See the configurations below for an example:

version: 2.1
jobs:
  hold:
    docker:
        - image: circleci/node:12
    steps:
      - run: printf "A hold job to wait for a manual approval"
  build:
    working_directory: ~/project
    docker:
      - image: circleci/node:12
    steps:
      - checkout
      - run: npm install

workflows:
  version: 2

  build-workflow:
    jobs:
      - hold:
          type: approval
      - build:
          requires:
            - hold

@muhammed-sayadi Thanks for the solution.

Can anyone from CircleCI team please help us here, is there any better way that we achieve this?

1 Like

@harshavardhanc while i dont work for CircleCI i am fairly certian that an approval job cannot have steps. you need to have a job dependant on the approval job that will run the steps you want.

In fact in the config here you can remove the job definition for hold and the config should still be valid and work fine.

1 Like