8000 Merge pull request #2894 from circleci/tjs/workflows-8-11-18 · stackbuilders/circleci-docs@f13ab16 · GitHub
  • [go: up one dir, main page]

    Skip to content
    This repository was archived by the owner on Apr 8, 2025. It is now read-only.

    Commit f13ab16

    Browse files
    Merge pull request circleci#2894 from circleci/tjs/workflows-8-11-18
    Workflow clarifications (manual approvals, updated config examples)
    2 parents f6dbe25 + 039ddd8 commit f13ab16

    File tree

    1 file changed

    +49
    -24
    lines changed

    1 file changed

    +49
    -24
    lines changed

    jekyll/_cci2/workflows.md

    Lines changed: 49 additions & 24 deletions
    Original file line numberDiff line numberDiff line change
    @@ -150,32 +150,54 @@ See the [Sample Fan-in/Fan-out Workflow config](https://github.com/CircleCI-Publ
    150150
    151151
    ## Holding a Workflow for a Manual Approval
    152152
    153-
    Workflows may be configured to wait for manual approval of a job before continuing by using the `type: approval` key. Anyone who has push access to the repository can click the Approval button to continue the workflow.
    153+
    Workflows can be configured to wait for manual approval of a job before
    154+
    continuing to the next job. Anyone who has push access to the repository can click the Approval button to continue the workflow.
    155+
    To do this, add a job to the `jobs` list with the
    156+
    key `type: approval`. Let's look at a commented config example.
    154157
    155-
    The `approval` job is a special job type that is **only** added to jobs under the `workflow` key. This enables you to configure a job with `type: approval` in the workflow before a set of jobs that must all wait for manual approval. Jobs run in the order defined until the workflow processes a job with the `type: approval` key followed by a job on which it depends as in the following `config.yml` example:
    158+
    ```yaml
    159+
    # ...
    160+
    # << Your config for the build, test1, test2, and deploy jobs >>
    161+
    # ...
    156162
    157-
    ```
    158163
    workflows:
    159164
    version: 2
    160165
    build-test-and-approval-deploy:
    161166
    jobs:
    162-
    - build
    163-
    - test1:
    164-
    requires:
    167+
    - build # your custom job from your config, that builds your code
    168+
    - test1: # your custom job; runs test suite 1
    169+
    requires: # test1 will not run until the `build` job is completed.
    165170
    - build
    166-
    - test2:
    167-
    requires:
    171+
    - test2: # another custom job; runs test suite 2,
    172+
    requires: # test2 is dependent on the succes of job `test1`
    168173
    - test1
    169-
    - hold:
    170-
    type: approval
    171-
    requires:
    174+
    - hold: # <<< A job that will require manual approval in the CircleCI web application.
    175+
    type: approval # <<< This key-value pair will set your workflow to a status of "On Hold"
    176+
    requires: # We only run the "hold" job when test2 has succeeded
    172177
    - test2
    178+
    # On approval of the `hold` job, any successive job that requires the `hold` job will run.
    179+
    # In this case, a user is manually triggering the deploy job.
    173180
    - deploy:
    174181
    requires:
    175182
    - hold
    176183
    ```
    177184

    178-
    In this example, the `deploy:` job will not run until you click the `hold` job in the Workflows page of the CircleCI app and then click Approve. Notice that the `hold` job must have a unique name that is not used by any other job. The workflow will wait with the status of On Hold until you click the job and Approve. After you approve the job with `type: approval`, the jobs which require the approval job will start. In the example above, the purpose is to wait for approval to begin deployment. To configure this behavior, the `hold` job must be `type: approval` and the `deploy` job must require `hold`.
    185+
    The outcome of the above example is that the `deploy:` job will not run until
    186+
    you click the `hold` job in the Workflows page of the CircleCI app and then
    187+
    click Approve. In this example the purpose of the `hold` job is to wait for
    188+
    approval to begin deployment.
    189+
    190+
    Some things to keep in mind when using manual approval in a workflow:
    191+
    192+
    - `approval` is a special job type that is **only** available to jobs under the `workflow` key
    193+
    - The `hold` job must be a unique name not used by any other job.
    194+
    - that is, your custom configured jobs, such as `build` or `test1` in the
    195+
    example above wouldn't be given a `type: approval` key.
    196+
    - The name of the job to hold is arbitrary - it could be `wait` or `pause`, for example,
    197+
    as long as the job has a `type: approval` key in it.
    198+
    - All jobs that are to run after a manually approved job _must_ `require:` the
    199+
    name of that job. Refer to the `deploy:` job in the above example.
    200+
    - Jobs run in the order defined until the workflow processes a job with the `type: approval` key followed by a job on which it depends.
    179201

    180202
    The following screenshots show a workflow on hold waiting for approval of the `request-testing` job:
    181203

    @@ -449,34 +471,37 @@ To persist data from a job and make it available to other jobs, configure the jo
    449471

    450472
    Configure a job to get saved data by configuring the `attach_workspace` key. The following `config.yml` file defines two jobs where the `downstream` job uses the artifact of the `flow` job. The workflow configuration is se 10000 quential, so that `downstream` requires `flow` to finish before it can start.
    451473

    452-
    ```
    453-
    # The following stanza defines a map named defaults with a variable that may be inserted using the YAML merge (<<: *) key
    454-
    # later in the file to save some typing. See http://yaml.org/type/merge.html for details.
    474+
    ```yaml
    475+
    # Note that the following stanza uses CircleCI 2.1 to make use of a Reusable Executor
    476+
    # This allows defining a docker image to reuse across jobs.
    477+
    # visit https://circleci.com/docs/2.0/reusing-config/#authoring-reusable-executors to learn more.
    455478
    456-
    defaults: &defaults
    457-
    working_directory: /tmp
    458-
    docker:
    459-
    - image: buildpack-deps:jessie
    479+
    version: 2.1
    480+
    481+
    executors:
    482+
    my-executor:
    483+
    docker:
    484+
    - image: buildpack-deps:jessie
    485+
    working_directory: /tmp
    460486
    461-
    version: 2
    462487
    jobs:
    463488
    flow:
    464-
    <<: *defaults
    489+
    executor: my-executor
    465490
    steps:
    466491
    - run: mkdir -p workspace
    467492
    - run: echo "Hello, world!" > workspace/echo-output
    468493
    469494
    # Persist the specified paths (workspace/echo-output) into the workspace for use in downstream job.
    470495
    - persist_to_workspace:
    471496
    # Must be an absolute path, or relative path from working_directory. This is a directory on the container which is
    472-
    # taken to be the root directory of the workspace.
    497+
    # taken to be the root directory of the workspace.
    473498
    root: workspace
    474499
    # Must be relative path from root
    475500
    paths:
    476501
    - echo-output
    477502
    478503
    downstream:
    479-
    <<: *defaults
    504+
    executor: my-executor
    480505
    steps:
    481506
    - attach_workspace:
    482507
    # Must be absolute path or relative path from working_directory
    @@ -490,7 +515,7 @@ jobs:
    490515
    fi
    491516

    492517
    workflows:
    493-
    version: 2
    518+
    version: 2.1
    494519

    495520
    btd:
    496521
    jobs:

    0 commit comments

    Comments
     (0)
    0