I believe my configuration is valid after reading the CircleCi workflow documentation but I am still getting the error below. What is wrong with my configuration?
Here is my workflow configuration:
workflows:
version: 2
build_assemble_deploy:
jobs:
- build
- assemble:
requires:
- build
filters:
branches:
only: master
- deploy:
requires:
- assemble
filters:
branches:
only: master
And here is the full error CircleCi gives me:
Build-agent version 0.1.799-f865b43f (2018-10-11T12:48:06+0000)
Configuration errors: 1 error occurred:
In step 2 definition: Invalid step structure (expected string or
map, got config.StepDescription)
The workflow configuration is fine. The issue is in the definition of step 2, in this case the definition of the assemble job. The definition is found in the configuration under job: > assemble:.
In this case the issue was an extra - character. This was the configuration:
- attach_workspace:
- at: ~/dir
The correct configuration is:
- attach_workspace:
at: ~/dir
Related
I have the following workflow definition for a CircleCI build
workflows:
version: 2
default:
jobs:
- verify
- tests_3_1:
requires:
- verify
- tests_5_0:
requires:
- verify
- pack:
requires:
- tests_3_1
- tests_5_0
- push:
requires:
- pack
context:
- GitHub
filters:
tags:
only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
branches:
ignore: /.*/
The idea is to:
run verify, test_3_1, test_5_0, pack on all commits
on top of the jobs above, run the job push when on master and with a tag that matches a semver version prepended by a v
For some reason no build is triggered when the commit is tagged. I am not sure if the problem is in the filter or in the regex not matching the build tags.
For now I tried v0.1.0-preview-0001 which matches on RegexPal.
Could you suggest any improvement? I see there is this question that is pretty similar but I have issues implementing the suggested solution
I solved this by specifying a tag regex filter for every job before push as shown in the documentation.
workflows:
version: 2
default:
jobs:
- verify:
filters:
tags:
only: /.*/
- tests_3_1:
requires:
- verify
filters:
tags:
only: /.*/
- tests_5_0:
requires:
- verify
filters:
tags:
only: /.*/
- pack:
requires:
- tests_3_1
- tests_5_0
filters:
tags:
only: /.*/
- push:
requires:
- pack
context:
- GitHub
filters:
tags:
only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
branches:
ignore: /.*/
I want to build a CircleCI workflow which builds and pushes to ECR only when I create a tagged release in Github.
I have the following CircleCI workflow:
workflows:
test-build-and-push-image:
jobs:
- get_python_dependencies
- unit_tests:
requires:
- get_python_dependencies
- aws-ecr/build-and-push-image:
name: build-and-push-to-ecr
repo: ${CIRCLE_PROJECT_REPONAME}
tag: ${CIRCLE_SHA1}
create-repo: true
requires:
- unit_tests
filters:
tags:
only: /.*/
branches:
ignore: /.*/
As I understand it, the filters on build-and-push-to-ecr are supposed to mean:
Run this job for any tag whatsoever
Don't run this job when pushing to any branch
But when I create a tagged release I get:
Why aren't my filters working?
A very close reading of the docs under Executing workflows for a git tag reveals a well-hidden detail:
if a job requires any other jobs (directly or indirectly), you must use regular expressions to specify tag filters for those jobs.
In other words, every job in the workflow must have the same filters for the build and push job to happen.
We can keep things a bit DRYer using & anchors:
workflows:
test-build-and-push-image:
jobs:
- get_python_dependencies:
filters: &tagged
# We only want to trigger this workflow on tags, not pushes to branches.
branches:
ignore: /.*/
tags:
# Trigger on every tag
only: /.*/
- unit_tests:
requires:
- get_python_dependencies
<<: *tagged
- aws-ecr/build-and-push-image:
name: build-and-push-to-ecr
repo: ${CIRCLE_PROJECT_REPONAME}
tag: ${CIRCLE_SHA1}
create-repo: true
requires:
- unit_tests
<<: *tagged
I have followed the guide described in Conditional steps in jobs and conditional workflows and written the below code for my CircleCI pipeline.
version: 2.1
workflows:
version: 2.1
workflowone:
when:
condition: false
jobs:
- samplejob:
workflowtwo:
when:
condition: true
jobs:
- jobone
jobs:
samplejob:
docker:
- image: buildpack-deps:stable
steps:
- run:
name: Sample Job in WF 1
command: |
echo "This job is in workflowone and the workflow should not run"
jobone:
docker:
- image: buildpack-deps:stable
steps:
- run:
name: Sample Job in WF 2
command: |
echo "This job is in workflowtwo and the workflow should run"
When I run the above code the output is not what is expected. First workflow should not run because the condition is false. Both worflows start running when the pipeline in triggered. Can anyone point out the missing piece here?
According to the CircleCI docs, workflows (specifically) does not accept the condition key:
Note: When using logic statements at the workflow level, do not
include the condition: key (the condition key is only needed for job
level logic statements).
See here logic-statement-examples (scroll to the bottom of this section to see the note)
Recently I've made some configuration on my team's github circleci. I needed to use a when statement to devide ci logics. I referenced this document(https://circleci.com/docs/2.0/configuration-reference/#logic-statements) but it seems the document not correct.
Below is my step definition:
...
image_build_step:
executor: golang_executor
steps:
- checkout
- setup_remote_docker:
version: 18.09.3
docker_layer_caching: true
- define_svc_name:
jobname: ${CIRCLE_JOB} # On this step set $SVC variable
- when:
conditon:
equal: ["${SVC}", "SVC_A" ]
- aws-ecr/build-and-push-image:
repo: SVC_A_REPO
dockerfile: ./Dockerfile
tag: "latest,${CIRCLE_SHA1},build-${CIRCLE_BUILD_NUM}"
...
Also I already tried this.
...
image_build_step:
executor: golang_executor
steps:
- checkout
- setup_remote_docker:
version: 18.09.3
docker_layer_caching: true
- define_svc_name:
jobname: ${CIRCLE_JOB} # On this step set $SVC variable
- when:
equal: ["${SVC}", "SVC_A" ]
- aws-ecr/build-and-push-image:
repo: SVC_A_REPO
dockerfile: ./Dockerfile
tag: "latest,${CIRCLE_SHA1},build-${CIRCLE_BUILD_NUM}"
...
I cannot figure out my mistake using when statement on circleci. Additionaly, I already passed circleci config validate .circleci/config.yaml command before I pushed this commit.
What is the correct usage of when statement in circleci? Joining circleci forum is also annoying me using github account, so I leave my question on stakeoverflow.
It's not possible to use environment variables in logic statements. The reason is that logic statements are evaluated at configuration compilation time, whereas environment variables are interpolated at run time.
The only workaround I know of is to use the CircleCI dynamic configuration functionality to set pipeline parameters' values in the "setup workflow" that you then pass to the "continuation" workflow.
I am trying to run sonarcloud-quality-gate check after performing sonarcloud-scan. I am doing this because I want bitbucket build pipeline should fail if the quality gate check is failed.
Doing this I get some error like this
Quality Gate failed: Could not get scanner report: [Errno 2] No such file or directory: '/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/sonarsource/sonarcloud-scan/sonarcloud-scan.log'
This is how my bitbucket.yml looks.
image: node:10.15.3
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- node
- sonar
script:
- npm install --quiet
- npm run test:coverage
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**.test.jsx" -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info'
- pipe: sonarsource/sonarcloud-quality-gate:0.1.1
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
pipelines:
default:
- step: *build-test-sonarcloud
Although solarcloud-scan pipe runs successfully.
The problem is that the sonarsource/sonarcloud-quality-gate pipe requires a newer version of the sonarsource/sonarcloud-scan pipe. (This was the case ever since the first release of the sonarsource/sonarcloud-quality-gate pipe.)
Change your pipeline configuration like this:
- pipe: sonarsource/sonarcloud-scan:1.0.1
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**.test.jsx" -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info'
- pipe: sonarsource/sonarcloud-quality-gate:0.1.3
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
An easy way to see the latest versions is in the pipeline editor.
When you edit the bitbucket-pipelines.yml file, a sidebar like this opens,
where you can filter the list by entering "sonar":
And then, click on a pipe to see details, and note the version used.