circleci-cli icon indicating copy to clipboard operation
circleci-cli copied to clipboard

Support default pipeline values when validating the config

Open sophiedophie opened this issue 5 years ago • 9 comments

  • [x] I have read Contribution Guidelines.
  • [x] I have checked for similar issues and haven't found anything relevant.
  • [x] This is not a security issue (which should be reported here: https://circleci.com/security/)

Do you want to request a feature or report a bug? Bug

What is the current behavior? cli config validation is failed with default pipeline variables (listed here: https://circleci.com/docs/2.0/pipeline-variables/#pipeline-values)

Can you provide an example?

version: 2.1

jobs:
  example:
    parameters:
      prev_rev:
        type: string
      rev:
        type: string
    docker:
      - image: circleci/node:4.8.2-jessie
    steps:
      - checkout
      - run: echo "<< parameters.prev_rev >> & << parameters.rev >> "


workflows:
  not_valid:
    jobs:
      - example:
          prev_rev: << pipeline.git.base_revision >>
          rev: << pipeline.git.revision >>

This returns

⇒  circleci config validate
Error: Error calling workflow: 'not_valid'
Unknown variable(s): base_revision, revision

What is the expected behavior? This should be valid config since it's basic parameters provided by CircleCI

Which version of the CLI and OS are you using? Did this work in previous versions?

Please provide the output of circleci version and circleci diagnostic.

⇒  circleci version
0.1.5879+416032d

If you have any questions, feel free to ping us at @CircleCI-Public/x-team.

sophiedophie avatar Feb 17 '20 07:02 sophiedophie

Logged as CIRCLE-25050

marcomorain avatar Mar 10 '20 12:03 marcomorain

This is still a problem with latest release.

>circleci version
0.1.6949+d951526

aadamovich avatar Mar 18 '20 09:03 aadamovich

Is there any estimate for this issue?

mczernek avatar May 06 '20 12:05 mczernek

This is fixed by #405 and has shipped in v0.1.7251. Also coming soon to Homebrew etc.

aengelberg avatar May 08 '20 19:05 aengelberg

@aengelberg this still seems to be an issue:

$ circleci-cli config validate
Error: Error calling workflow: 'build-and-deploy'
Error calling job: 'build-and-publish-image'
Unknown variable(s): base_revision

Running latest 0.1.8302

You want me to file a new issue?

pmyjavec avatar Jun 18 '20 13:06 pmyjavec

@aengelberg @pmyjavec Workflows still cannot access << pipeline.xxx >> parameters defined outside of workflows during config validation

commands:
  setup-env:
    steps:
      - run:  echo "export BUILD_NUMBER=<< pipeline.number >>" >> $BASH_ENV
...
workflows:
  SOME-WF:
    jobs:
      - some-job:
          pre-steps:
            - checkout
            - setup-env

Results in:

$ circleci config validate
Error: Error calling workflow: 'SOME-WF'
Error calling job: 'some-job'
Error calling command: 'setup-env
Unknown variable(s): number

zumby avatar Mar 09 '21 10:03 zumby

It looks like this fix was removed from the code as part of https://github.com/CircleCI-Public/circleci-cli/pull/408 while updating the tests to use cucumber.

Xavientois avatar Oct 27 '21 20:10 Xavientois

I am getting this error too:

I have a job in the workflow which looks like:

...

  bump_version:
    docker:
      - image: cimg/node:16.13.0
    parameters:
      version:
        type: string
    steps:
      - checkout
      - run: 
          command: |
            git pull origin
            git checkout main
            echo "Updating package.json version"
            yarn version --new-version << parameters.version >>
            git add .
            git commit -m "Updating to version << parameters.version >> - [skip ci]"
            git push
            echo "Creating and pushing tag to trigger release deployment to prod"
            git tag -a deploy@<< parameters.version >> -m "Tag to trigger << parameters.version >> deployment to prod"
            git push origin deploy@<< parameters.version >> 

only_on_release_tag: &only_on_release_tag
  filters:
    tags:
      only: /^0.*/
    branches:
      ignore: /.*/

...

on_release_tag:
    jobs:
      - bump_version:
          <<: *only_on_release_tag
          version: << pipeline.git.tag >>

Locally the circleci validate config is passing but once pushed I get

#!/bin/sh -eo pipefail
# Error calling workflow: 'on_release_tag'
# Error calling job: 'bump_version'
# Unknown variable(s): version
# 
# -------
# Warning: This configuration was auto-generated to show you the message above.
# Don't rerun this job. Rerunning will have no effect.
false

Apparently works only if I provide a default. Which in my case is empty "".

Vanals avatar Mar 17 '22 17:03 Vanals

Hi there!

I would like to confirm that there is a regression in circleci CLI regarding this issue again. Here is our case. We are creating our own orb and we use other CircleCI orbs to validate/publish this orb to our CircleCI organization. In the orb that I am working, I have one of the jobs defined as following in the orb.yml file:

  ...
  zip-lambda-code-artifact:
    <<: *common_python_job_parameters #TODO: Can be any other really
    description: Bundles all code found in 'working_directory' into a ZIP file and persists it in a CircleCI workspace
    steps:
      # No checkout step here as we want to rely on CCI workspaces and it is left to jobs specific to runtime (*-lambda-quality-validations) to persist packages & dependencies ready to be zipped
      - attach_workspace:
          at: $CIRCLE_WORKING_DIRECTORY
      - run:
          name: Zip Lambda code artifact
          command: |
            shopt -s extglob
            mkdir bundle
            cp -r !(bundle) bundle/
            cd bundle/
            zip -r << pipeline.git.revision >>.zip
      - persist_to_workspace:
          root: . # This matches 'working_directory' parameter for the job
          paths:
            - '/**'

Notice the use of << pipeline.git.revision >> global pipeline parameter in the orb in the run step. In the CircleCI workflow that is responsible to publish this orb to our CircleCI org ( dev: orb environment ), the following step is executed (note that it uses circleci CLI ):

#!/bin/bash -eo pipefail
circleci orb publish --skip-update-check ./orb.yml skywardio/lambda@dev:${CIRCLE_SHA1} --token $CIRCLE_TOKEN 

Error: Error calling job: 'zip-lambda-code-artifact'
Unknown variable(s): revision

Exited with code exit status 255

CircleCI received exit code 255

I have confirmed that job which executes above step to publish orb uses latest available Docker image with circleci CLI. As a matter of fact, here is the full dump of the "Spin up environment" job which shows the use of the latest Docker image for circleci CLI:


Build-agent version 1.0.118328-f91ea032 (2022-04-08T13:50:21+0000)
System information:
 Server Version: 20.10.14
 Storage Driver: overlay2
  Backing Filesystem: xfs
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Kernel Version: 5.13.0-1017-aws
 Operating System: Ubuntu 20.04.4 LTS
 OSType: linux
 Architecture: x86_64

Starting container circleci/circleci-cli:latest                   <---------------------------------HERE
Warning: No authentication provided, using CircleCI credentials for pulls from Docker Hub.
  image cache not found on this host, downloading circleci/circleci-cli:latest           <---------------------------------HERE
latest: Pulling from circleci/circleci-cli

f04beb70: Already exists 
093a898c: Already exists 
a045c926: Already exists 
e24d4dac: Already exists 
c9787a2f: Pulling fs layer 
653f6388: Pulling fs layer 
6b19f797: Pulling fs layer 
be41cc4c: Pulling fs layer 
1df0a0e8: Pulling fs layer 
3e33ca0a: Pulling fs layer 
5e974c15: Pulling fs layer 
8556bc69: Pulling fs layer 
ba9251cd: Pulling fs layer 
b81e4b83: Pulling fs layer 
89002d17: Pulling fs layer 
6edff8c4: Pulling fs layer 
Digest: sha256:42e4b9cda16481842ad3a40377e6bbcf75f69c2e9058df7eff02994e1900f5d531MB/5.131MBB
Status: Downloaded newer image for circleci/circleci-cli:latest                 <---------------------------------HERE
circleci/circleci-cli:latest:
  using image circleci/circleci-cli@sha256:42e4b9cda16481842ad3a40377e6bbcf75f69c2e9058df7eff02994e1900f5d5
  pull stats: download 321MiB in 3.512s (91.38MiB/s), extract 320.8MiB in 5.808s (55.24MiB/s)
  time to create container: 338ms
Time to upload agent and config: 339.085647ms
Time to start containers: 519.994843ms

I have tried running the same command locally using my local (installed via Homebrew) circleci CLI. I am getting the same error.

Local circleci CLI version:

$ circleci version

0.1.16947+263902a (homebrew)

Local attempt to publish orb using circleci CLI:

$ circleci orb publish --skip-update-check ./orb.yml skywardio/lambda@dev:b25c46efaea2d7f27eabe67aabfd7d7f1fd9eb15 --token $CIRCLECI_TOKEN

Error: Error calling job: 'zip-lambda-code-artifact'
Unknown variable(s): revision

azec-pdx avatar Apr 08 '22 23:04 azec-pdx