Config.yml conditional for build and deploying multiple environments

I have been reading docs and discussion. I would like to be able to turn off and on deployments to Cloudsmith from a single line in config.yml Additionally I would like to turn off all builds with a single variable at the top and then change the conditional value for the environment that is being tested. This is as far as I have gotten. Something is missing because deployments are still occurring (first step). This is a portion of the file. Any suggestions?

version: 2.1

parameters:
  run_workflow_build:
    type: boolean
    default: false
  deploy:
    type: boolean
    default: false

jobs:
    build-armhf-stretch:
        machine: true
        environment:
        - OCPN_TARGET=stretch-armhf
        - DOCKER_IMAGE=jongough/raspbian-stretch:latest
        - BUILD_FLAGS=-j3
        - BUILD_ENV=raspbian
        steps:
        - checkout
        - run: chmod a+x ./ci/*.sh
        - run:
            command: ci/circleci-build-raspbian-armhf.sh
            no_output_timeout: 30m
        - when:
            condition: << pipeline.parameters.deploy >>
            steps:
              - run: ci/cloudsmith-upload.sh
              - run: echo "deploying"
    build-armhf-buster:
        machine: true
        environment:
        - OCPN_TARGET=buster-armhf
        - DOCKER_IMAGE=jongough/raspbian-buster:plugin_build_tooling_current
        - BUILD_FLAGS=-j3
        - BUILD_ENV=raspbian
        steps:
        - checkout
        - run: chmod a+x ./ci/*.sh
    - run:
        command: ci/circleci-build-raspbian-armhf.sh
        no_output_timeout: 30m
    - when:
        condition: << pipeline.parameters.deploy >>
        steps:
          - run: ci/cloudsmith-upload.sh
          - run: echo "deploying"

workflows:
version: 2
build_all:
    jobs:
    - build-armhf-stretch:
        filters:
            branches:
                ignore:
                - devel
                - tmp
            tags:
                only: /.*/
    - build-armhf-buster:
        filters:
            branches:
                ignore:
                - devel
                - tmp
            tags:
                only: /.*/

Here is the full yml file

It is strange, because the circleci pipeline build results do not show confirmation of deployment and do not appear to show run of “cloudsmith-upload.sh” yet the builds are being deployed to Cloudsmith!

The deployment of the two raspbian builds to Cloudsmith is successfully being prevented.
Now I will add this code to all environments.

Then try to control the builds.

This works for stopping deployment, now I just have to control the .travis and appveyor builds through their yml. Next job is preventing builds.

parameters:
  run_workflow_build:
    type: boolean
    default: false
  run_workflow_deploy:
    type: boolean
    default: false

jobs:
    build-armhf-stretch:
        machine: true
        environment:
        - OCPN_TARGET=stretch-armhf
        - DOCKER_IMAGE=jongough/raspbian-stretch:latest
        - BUILD_FLAGS=-j3
        - BUILD_ENV=raspbian
        steps:
        - checkout
        - run: chmod a+x ./ci/*.sh
        - run:
            command: ci/circleci-build-raspbian-armhf.sh
            no_output_timeout: 30m
        - when:
            condition: <<pipeline.parameters.run_workflow_deploy>>
            steps:
              - run: ci/cloudsmith-upload.sh
              - run: echo "deploying"

I have been trying to conditionally control the builds for different environments, and have shortened the config.yml to simplify things. I’ve made a number of changes but the yml is still not accepted with this second conditional for building.

---
version: 2.1
parameters:
  run_workflow_build:
    type: boolean
    default: false
  run_workflow_deploy:
    type: boolean
    default: false
jobs:
  build-armhf-stretch:
    machine: true
    environment:
      - OCPN_TARGET=stretch-armhf
      - 'DOCKER_IMAGE=jongough/raspbian-stretch:latest'
      - BUILD_FLAGS=-j3
      - BUILD_ENV=raspbian
    steps:
      - when:
          condition: << pipeline.parameters.run_workflow_build >>
      - checkout
      - run: chmod a+x ./ci/*.sh
      - run:
          command: ci/circleci-build-raspbian-armhf.sh
          no_output_timeout: 30m
      - when:
          condition: <<pipeline.parameters.run_workflow_deploy>>
          steps:
            - run: ci/cloudsmith-upload.sh
            - run: echo "deploying"
workflows:
  version: 2
  build_all:
    jobs:
      - build-armhf-stretch:
          filters:
            branches:
              ignore:
                - devel
                - tmp
            tags:
              only: /.*/

When I run this the error is as follows:

#!/bin/sh -eo pipefail
# ERROR IN CONFIG FILE:
# [#/jobs/build-armhf-stretch] 0 subschemas matched instead of one
# 1. [#/jobs/build-armhf-stretch] only 1 subschema matches out of 2
# |   1. [#/jobs/build-armhf-stretch/steps/0] 0 subschemas matched instead of one
# |   |   1. [#/jobs/build-armhf-stretch/steps/0] expected type: String, found: Mapping
# |   |   |   Shorthand commands, like `checkout`
# |   |   |   SCHEMA:
# |   |   |     type: string
# |   |   |   INPUT:
# |   |   |     when:
# |   |   |       condition: << pipeline.parameters.run_workflow_build >>
# |   |   2. [#/jobs/build-armhf-stretch/steps/0/when] only 1 subschema matches out of 2
# |   |   |   1. [#/jobs/build-armhf-stretch/steps/0/when] subject must not be valid against schema {\"pattern\":\"^(when|unless)$\"}
# |   |   |   |   SCHEMA:
# |   |   |   |     not:
# |   |   |   |       pattern: ^(when|unless)$
# |   |   |   |   INPUT:
# |   |   |   |     condition: << pipeline.parameters.run_workflow_build >>
# |   |   3. [#/jobs/build-armhf-stretch/steps/0/when] required key [steps] not found
# 2. [#/jobs/build-armhf-stretch] expected type: String, found: Mapping
# |   Job may be a string reference to another job
# 
# -------
# Warning: This configuration was auto-generated to show you the message above.
# Don't rerun this job. Rerunning will have no effect.
false


Exited with code exit status 1

CircleCI received exit code 1

Any suggestions?

Config.yml now

Error Result

@rgleason :wave:

The issue with the config is around Line 21. Here you have specified a condition, but you have not specified the steps that should be executed when the condition is met.

For example, instead of:

...
    steps:
      - when:
          condition: << pipeline.parameters.run_workflow_build >>
      - checkout
...

It should be something like:

...
    steps:
      - when:
          condition: << pipeline.parameters.run_workflow_build >>
          steps:
            - run: echo "Hello, World!"
      - checkout
...

Once you add the steps in the when step, it should pass config validation.

I hope this helps!

Thank you bytesguy! Your suggestion made me change to this configuration. Which is building now! Next will will change the parameters to false and see what happens.
Thank you for getting me back on track!

---
version: 2.1
parameters:
  run_workflow_build:
    type: boolean
    default: true
  run_workflow_deploy:
    type: boolean
    default: true
jobs:
  build-armhf-stretch:
    machine: true
    environment:
      - OCPN_TARGET=stretch-armhf
      - 'DOCKER_IMAGE=jongough/raspbian-stretch:latest'
      - BUILD_FLAGS=-j3
      - BUILD_ENV=raspbian
    steps:
      - when:
          condition: <<pipeline.parameters.run_workflow_build>>
          steps:
            - checkout 
            - run: chmod a+x ./ci/*.sh
            - run:
               command: ci/circleci-build-raspbian-armhf.sh
               no_output_timeout: 30m
      - when:
          condition: <<pipeline.parameters.run_workflow_deploy>>
          steps:
            - run: ci/cloudsmith-upload.sh
            - run: echo "deploying"
workflows:
  version: 2
  build_all:
    jobs:
      - build-armhf-stretch:
          filters:
            branches:
              ignore:
                - devel
                - tmp
            tags:
              only: /.*/
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.