Executing a CircleCI job only when tag matches a certain pattern - circleci

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: /.*/

Related

bitbucket pipelines variables in line

It is possible to declare variables inside the pipeline file, as in this GitHub example:
# ...
env:
NODE_VERSION: 16.3.1
FOLDER_PATH: Project
# ...
steps:
- name: Move to project folder
run: cd $FOLDER_PATH
# ...
Is it possible to do something similar in the bitbucket pipeline files? (How?)
Thanks any help : )
No.
There is a feature request for that https://jira.atlassian.com/browse/BCLOUD-17453 .
Still "gathering interest" though.
The nearest approximation is to write a YAML anchor that exports those vars and use it in every step.
definitions:
yaml-anchors:
- &setenv-script >-
export NODE_VERSION=16.3.1
&& export FOLDER_PATH=Project
pipelines:
default:
- step:
script:
- *setenv-script
- ...
- step:
script:
- *setenv-script
- ...

Chromatic deployment error when using github-actions

I am working on a React project which is using storybook, I'm trying to publish this storybook into chromatic with GitHub actions. I am using their sample chromatic.yml with just a few changes to match my project needs. Running the chromatic-cli my storybook is desployed succesflly but when I use GitHub actions the following error is displayed:
Error: ✖ Failed to collect Storybook metadata
Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
Here's the full error log:
Run chromaui/action#v1
with:
projectToken: ***
Chromatic CLI v5.7.0
https://www.chromatic.com/docs/cli
Authenticating with Chromatic
→ Connecting to https://index.chromatic.com
Authenticated with Chromatic
→ Using project token '********119f'
Retrieving git information
Retrieved git information
→ Commit 'a9f9af7' on branch 'master'; found 1 baseline commit
Collecting Storybook metadata
→ Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
✖ Failed to collect Storybook metadata
Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
→ View the full stacktrace below
If you need help, please chat with us at https://www.chromatic.com/docs/cli for the fastest response.
You can also email the team at support#chromatic.com if chat is not an option.
Please provide us with the above CLI output and the following info:
{
"timestamp": "2021-04-23T22:03:58.789Z",
"sessionId": "2f736280-50df-4f2e-aa3d-00d90236cf61",
"gitVersion": "2.31.1",
"nodePlatform": "linux",
"nodeVersion": "12.13.1",
"packageName": "chromatic",
Error: non-zero exit code
"packageVersion": "5.7.0",
"flags": {
"projectToken": "***",
"fromCI": true,
"interactive": false,
"exitZeroOnChanges": true,
"exitOnceUploaded": false,
"allowConsoleErrors": false
},
"buildScript": "build-storybook",
"errorType": "Error",
"errorMessage": "✖ Failed to collect Storybook metadata"
}
Error: ✖ Failed to collect Storybook metadata
Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
at /home/runner/work/_actions/chromaui/action/v1/bin/lib/getStorybookInfo.js:83:11
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async getStorybookInfo (/home/runner/work/_actions/chromaui/action/v1/bin/lib/getStorybookInfo.js:115:25)
at async setStorybookInfo (/home/runner/work/_actions/chromaui/action/v1/bin/tasks/storybookInfo.js:6:42)
at async Task.task (/home/runner/work/_actions/chromaui/action/v1/bin/lib/tasks.js:13:7)
And this is my chromatic.yml
# Workflow name
name: "Chromatic Deployment"
# Event for the workflow
on:
push:
branches: [master, stagging, developing]
pull_request:
branches: [master, stagging, developing]
# List of jobs
jobs:
test:
# Operating System
runs-on: ubuntu-latest
defaults:
run:
working-directory: foo
# Job steps
steps:
- uses: actions/checkout#v1
- run: yarn
#👇 Adds Chromatic as a step in the workflow
- uses: chromaui/action#v1
# Options required for Chromatic's GitHub Action
with:
#👇 Chromatic projectToken, see https://storybook.js.org/tutorials/intro-to-storybook/react/en/deploy/ to obtain it
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
So here's what I found on chromatic's official repository:
https://github.com/chromaui/chromatic-cli/issues/227
https://github.com/chromaui/chromatic-cli/issues/324
https://github.com/chromaui/chromatic-cli/issues/197
There's a chance this problem originates from the fact I'm using a monorepo, I though using working-directory was enough to fix this but there an aditional parameter to be used chromaui, workinDir.
Here's my current chromatic.yml
# Workflow name
name: "Chromatic Deployment"
# Event for the workflow
on:
push:
branches: [master, stagging, developing]
pull_request:
branches: [master, stagging, developing]
# List of jobs
jobs:
chromatic-deployment:
# Operating System
runs-on: ubuntu-latest
defaults:
run:
working-directory: foo
# Job steps
steps:
- uses: actions/checkout#v1
- run: yarn
#👇 Adds Chromatic as a step in the workflow
- uses: chromaui/action#v1
# Options required for Chromatic's GitHub Action
with:
workingDir: foo
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

CircleCI reports "No workflow" when creating a tagged release

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

Invalid step structure

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

Triggering different downstream jobs via templates in Jenkins Job Builder

I'm trying to trigger one or more downstream jobs using a job template. A summary of my definition:
- job-template:
name: something-{app}-build
project-type: freestyle
defaults: global
block-downstream: true
scm:
- git:
url: url
branches:
- 'master'
excluded-users:
- Jenkins
builders:
!include: templates/build-and-publish.yml
publishers:
- postbuildscript:
builders:
!include: templates/docker-build-and-push-to-ecr.yml
script-only-if-succeeded: True
mark-unstable-if-failed: True
- trigger-parameterized-builds:
- project: 'deploy-dev-ecs-service'
condition: SUCCESS
predefined-parameters: |
service={app}
envparams={envparams}
- project:
name: release-to-ecr
type: app
envparams: ''
app:
- app-1
- app-2:
- app-3:
envparams: 'FOO=42'
jobs:
- 'something-{app}-build'
Now this works, but I need to trigger different downstream jobs based on the app. This means triggering deploy-dev-ecs service multiple times with multiple parameters. For example:
app:
- app-1:
- project: deploy-dev-ecs-service
service: 'app-1'
envparams: 'foo=bar'
- app-2:
- project: deploy-dev-ecs-service
service: 'app-2.2'
envparams: 'x=2'
- project: deploy-dev-ecs-service
service: 'app-2.3'
envparams: 'x=3'
Essentially, I need to control which downstream job(s) get triggered based on
the project parameters. Is there a way to do this?

Resources