Conditional Workflow: allOf error

Hola guys,

This tutorial: link explain how to trigger a pipeline from github actions and specify how to protect us for duplicated executions. In the tutorial we can see we have to add the following code to our config file:

workflows:
  # This workflow is set to be triggered conditionally, only when
  # the GitHub Action is triggered.
  # With no other workflows, normal push events will be ignored.
  when: << pipeline.parameters.GHA_Action >>
  test:
    jobs:
      - test

But in the Linter console I am getting the following error:

ERROR IN CONFIG FILE:
[#/workflows/when] only 0 subschema matches out of 2
1. [#/workflows/when] expected type: Mapping, found: String
|   SCHEMA:
|     type: object
|   INPUT:
|     << pipeline.parameters.GHA_Action >>
2. [#/workflows/when] subject must not be valid against schema {"description":"cannot use both 'when' and 'unless'","allOf":[{"required":["when"]},{"required":["unless"]}]}
|   SCHEMA:
|     not:
|       description: cannot use both 'when' and 'unless'
|       allOf:
|       - required:
|         - when
|       - required:
|         - unless
|   INPUT:
|     << pipeline.parameters.GHA_Action >>

This is the code I have in my config file:

version: 2.1
parameters:
  GHA_Event:
    type: string
    default: ""
  GHA_Actor:
    type: string
    default: ""
  GHA_Action:
    type: string
    default: ""
orbs:
  python: circleci/python@1.5.0
  slack: circleci/slack@4.10.1
jobs:
  tests:
    docker:
      - image: cimg/python:3.7
    steps:
      - checkout
      - run: ""
workflows:
  version: 2
  when: << pipeline.parameters.GHA_Action >>
  ci-tests:
    jobs:
      - tests

Is almost the same as the tutorial. Could you help me to realize what I am doing wrong. Thank so much!

I realized that what I was doing wrong is: I overwrite the version into the workflows part. So part of the config uses version 2.1 and the other one uses version 2. As the when statement was included in the version 2.1 I was getting and invalid schema.

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