Can't get CircleCI to post to Slack upon test failure - cypress

I'm getting no parsing errors and i believe my config.yml is correct, I just can't seem to get it to post to slack, i have all the backgrounc config correct such as the environment variables and the context part is what we call to our organization settings, it's just not posting upon failure, is there something i'm doing wrong?
version: 2.1
orbs:
cypress: cypress-io/cypress#1
slack: circleci/slack#4.5.0
workflows:
version: 2
test:
jobs:
- cypress/run
jobs:
steps:
executors:
with-chrome:
docker:
- image: 'cypress/browsers:node14.16.0-chrome90-ff88'
description: Runs cypress tests
steps:
- checkout
- run:
name: Run all cypress tests
command: npx cypress run
context: slack-context
- slack/notify:
event: fail
template: basic_fail_1

It appears you're using the CircleCI Cypress orb, and more specifically the cypress/run job defined in that orb. So I'm not sure what the part
jobs:
steps:
executors:
with-chrome:
docker:
- image: 'cypress/browsers:node14.16.0-chrome90-ff88'
description: Runs cypress tests
steps:
- checkout
- run:
name: Run all cypress tests
command: npx cypress run
context: slack-context
- slack/notify:
event: fail
template: basic_fail_1
is for.
The way your config looks, that part will never be executed. Your build will be simply the cypress/run job running with all the default parameters' values.
Further more, contexts need to be referenced within the workflows section (https://circleci.com/docs/2.0/contexts/).
I would suggest the below configuration:
version: 2.1
orbs:
cypress: cypress-io/cypress#1.29.0
slack: circleci/slack#4.10.1
executors:
with-chrome:
docker:
- image: 'cypress/browsers:node14.16.0-chrome90-ff88'
workflows:
version: 2
test:
jobs:
- cypress/run:
executor: with-chrome
browser: chrome
context: slack-context
post-steps:
- slack/notify:
event: fail
template: basic_fail_1

Related

Cypress Github Action Fail-The process '/usr/bin/npx' failed with exit code 1

I use GitHub Action for CI/CD, I write some cypress tests and YAML files from it. But when I push the repository I got an error.
name: Testing EDGE Portal
runs-on: self-hosted
needs: [deploy_edge_service]
steps:
- name: Install node
uses: actions/setup-node#v3
with:
node:version: '16'
- name: setup cypress env
run: |
echo "setup cypress env"
- name: run all test
uses: cypress-io/github-action#v5
with:
start: npm start
working-directory: ./integration_test/NetProbe_E2E/cypress
command: npx cypress run --env grepTags="#trap #probe"
The failing error
enter image description here
How I fix that problem.

sh: 1: nest: Permission denied in GitHub Action

For some reason the build step for my NestJS project in my GitHub Action fails for a few days now. I use Turborepo with pnpm in a monorepo and try to run the build with turbo run build. This works flawlessly on my local machine, but somehow in GitHub it fails with sh: 1: nest: Permission denied. ELIFECYCLE  Command failed with exit code 126. I'm not sure how this is possible, since I couldn't find any meaningful change I made to the code in the meantime. It just stopped working unexpectedly. I actually think it is an issue with GH Actions, since it actually works in my local Docker build as well.
Has anyone else encountered this issue with NestJS in GH Actions?
This is my action yml:
name: Test, lint and build
on:
push:
jobs:
test-lint-build:
runs-on: ubuntu-latest
services:
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_HOST: localhost
POSTGRES_USER: test
POSTGRES_PASSWORD: docker
POSTGRES_DB: financing-database
ports:
# Maps tcp port 5432 on service container to the host
- 2345:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Install pnpm
uses: pnpm/action-setup#v2.2.2
with:
version: latest
- name: Install
run: pnpm i
- name: Lint
run: pnpm run lint
- name: Test
run: pnpm run test
- name: Build
run: pnpm run build
env:
VITE_SERVER_ENDPOINT: http://localhost:8000/api
- name: Test financing-server (e2e)
run: pnpm --filter #project/financing-server run test:e2e
I found out what was causing the problem. I was using node-linker = hoisted to mitigate some issues the pnpm way of linking modules was causing with my jest tests. Removing this from my project suddenly made the action work again.
I still don't know why this only broke the build recently, since I've had this option activated for some time now.

CircleCI getting an error on running a make command

I want to config.yml that has a "build" and "test" jobs.
We have a Makefile in our docker image but it seems it's not finding the make file since I'm always getting this error
#!/bin/bash -eo pipefail
make test
make: *** No rule to make target 'test'. Stop.
Exited with code exit status 2
CircleCI received exit code 2
Is anyone familiar with this? I'm not sure what I have missed.
Thank you!
Here is the yml file:
version: 2.1
workflows:
my-workflow:
jobs:
- build:
context: circleci-aws-credentials
- test
jobs:
build:
docker:
- image: circleci/openjdk:11-jdk
working_directory: ~/my-project
environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
steps:
- checkout
# Download and cache dependencies
- restore_cache:
key: my-project-service-{{ checksum "./build.gradle" }}
test:
docker:
- image: circleci/openjdk:11-jdk
working_directory: ~/my-project
environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
steps:
- run:
name: Gradle test
command: make test
- store_test_results:
path: ./build/test-results
Thank you for your help in advance!

How to run docker in Ciricle CI orbs?

CircleCI introduces orb in 2.1, I am trying to add Circle Ci config my sample project.
But in my testing codes, I have used test containers to simplify the dependent config of my integration tests.
When committing my codes, the Circle CI running is failed.
org.testcontainers.containers.ContainerLaunchException: Container startup failed
Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=mongo:4.0.10, imagePullPolicy=DefaultPullPolicy())
Caused by: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
My Circle CI config.
version: 2.1
orbs:
maven: circleci/maven#1.0.1
codecov: codecov/codecov#1.1.0
jobs:
codecov:
machine:
image: ubuntu-1604:201903-01
steps:
- codecov/upload
workflows:
build:
jobs:
- maven/test:
command: "-q verify -Pcoverage"
- codecov:
requires:
- maven/test
Got it run myself.
The maven orb provides reusable jobs and commands, but by default, it used a JDK executor, does not provide a Docker runtime.
My solution is giving up the reusable job, and reuse some commands from the maven orb in your own jobs.
version: 2.1
orbs:
maven: circleci/maven#1.0.1
codecov: codecov/codecov#1.1.0
executors:
docker-mongo:
docker:
- image: circleci/openjdk:14-jdk-buster
- image: circleci/mongo:latest
jobs:
build:
executor: docker-mongo
steps:
- checkout
- maven/with_cache:
steps:
- run: mvn -q test verify -Pcoverage
- maven/process_test_results
- codecov/upload:
when: on_success
workflows:
build:
jobs:
- build

Runnig tasks only when merging to master

I use the following config which works as expected, it run the command on each PR or merge to the master, Now I want to make some integration test which I want to run only when merged to the master, all the PR should remain the same (and run the following config as before). the nuance here is that for the integration test I need other docker image and different run command to execute (which should execute only when merging to the master), is it possible to do it with CircleCI ?
# Golang CircleCI 2.0 configuration file
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.11
working_directory: /go/src/sbr
steps:
- checkout
- run: go version
- run: go env
- run: go get -v -t -d ./...
- run: go test -v ./...
I try to add another docker image under the existing one but I got error
update:
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.11
working_directory: /go/src/sbr
steps:
- checkout
- run: go version
- run: go env
- run: go get -v -t -d ./...
- run: go test -v ./...
test-integration:
docker:
- image: other-image
workflows:
version: 2
builds:
jobs:
- build
integration-test:
jobs:
- test-integration:
requires:
- build
filters:
branches:
only: master
The issue here that I got error when adding to the second workflow the require
requires:
- build
I want that before the test test-integration it will also run the build job as per-requiste . what im doing wrong ?
The error is:
requires job \"build\" but \"build\" is not part of this workflow.
# At least one job in the workflow must have no dependencies.
# The following jobs are unreachable: integration
#
# -------
# Don't rerun this job. Rerunning will have no effect.
false
Your configuration has a single job named build and no workflows. It sounds like what you want is to run a second job for integration tests, and to have the second job only run when the branch is master. To accomplish both of those you would use a workflow with two jobs.
See https://circleci.com/docs/2.0/configuration-reference/#workflows
An example of what that might look like:
jobs:
build:
docker:
- image: circleci/golang:1.11
...
test-integration:
docker:
- image: other-image
...
workflows:
version: 2
workflow-name:
jobs:
- build
- test-integration:
filters:
branches:
only: master

Resources