Cirrus CI notify email on failed build - continuous-integration

I have hosted my source code on github and added a trigger on each check in. When the trigger is triggered, the Cirrus-CI build tool starts to build my component. to achive this, github must be setup properly and each component must have a valid .cirrus.yml file, who is responsible for the build setup.
how can i change my config file so that i get a notification whenever my build fails?
Here is my .cirrus.yml file:
container:
image: maven:latest
build_task:
build_script: mvn clean compile test sonar:sonar
yes, it is rather short and on the Cirrus-CI help page are explanations concering email notification and writing conditional tasks but I don't see how i can get the build result and create a condition on that.

the solution is simple as can be:
container:
image: maven:latest
build_task:
build_script: mvn clean compile test sonar:sonar
on_failure:
mail_script: mvn postman:send-mail
this requires the postman mail plugin in your pom.xml.

Related

CircleCI runs zero tests on my maven Java project

I have a test project that is built with Maven (Java). I can either execute the test from IntelliJ manually or from the command line by writing mvn test.
I put the project on CircleCI and it generated a yml file. And it was able to execute the tests on pipelines as well without any issue at first
Then I made something stupid. Initially tests were in this root: src/main/java/api/test. But I decided to move the test class to this root: src/test/java/api.
I did this change because src/test/java was the actual test folder created automatically when you create a Maven project. (The other test folder was created by me manually so I thought this was not the best practice and therefore decided to move the test class to src/test/java. Basically what I did is, I created a package named api under src/test/java and moved the test class to this package. After that I deleted src/main/java/api/test as it is empty now.
After this change, I didn't observe any issue. I could still run the tests from IntelliJ or from the command line by mvn test command. But after I commit my changes, I just checked the pipelines and saw this:
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.793
My project is still built and tested on CircleCI but it obviously does not execute the test class. I dont know why it is happening. I checked the yml file and there is nothing related with paths and it was working before. Here is my yml file:
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1
jobs:
# Below is the definition of your job to build and test your app, you can rename and customize it as you want.
build-and-test:
# These next lines define a Docker executor: https://circleci.com/docs/2.0/executor-types/
# You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# Be sure to update the Docker image tag below to openjdk version of your application.
# A list of available CircleCI Docker Convenience Images are available here: https://circleci.com/developer/images/image/cimg/openjdk
docker:
- image: cimg/openjdk:11.0
steps:
# Checkout the code as the first step.
- checkout
# Use mvn clean and package as the standard maven build phase
- run:
name: Build
command: mvn -B -DskipTests clean package
# Then run your tests!
- run:
name: Test
command: mvn test
workflows:
# Below is the definition of your workflow.
# Inside the workflow, you provide the jobs you want to run, e.g this workflow runs the build-and-test job above.
# CircleCI will run this workflow on every commit.
# For more details on extending your workflow, see the configuration docs: https://circleci.com/docs/2.0/configuration-reference/#workflows
sample:
jobs:
- build-and-test
As I said the same yml file was working fine before I moved the test class. Now it probably can not locate my test file. What could be the problem here and how can I solve this? Any help is appreciated.

Break Push in GitLab based on SonarQube Analysis Result

I have an application in springboot which uses gradle to build the code.
I have setup https://github.com/gabrie-allaigre/sonar-gitlab-plugin on SonarQube and have integrated gitlab CI
to analyse code on every push/commit. What I want to achieve is to break the push/commit if the analysis fails.
Below is my .gitlab-ci.yml
image: XXXXXX:oraclejdk:1.8.0_121
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
sonarqube_master_job:
stage: test
only:
- master
- release2.0
script:
- ./gradlew assemble
- ./gradlew -x test sonarqube -Dsonar.host.url=http://sonarqube.XXX.XXX.XXX:9000/sonarqube -Dsonar.login=xxxxxxxxxxxxxxxxxxxx
sonarqube_preview_feature_job:
stage: test
only:
- /^feature\/*/
- development
script:
- git checkout $CI_COMMIT_REF_NAME
- git merge --no-commit --no-ff
- ./gradlew assemble
- ./gradlew -x test sonarqube -Dsonar.host.url=http://XXXX.XXXXX.com:9000/sonarqube -Dsonar.login=xxxxxxxxxxxxxxxxxxxxx -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$CI_COMMIT_REF -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID --stacktrace
How do I make sure the push fails if the analysis fails? Do I need to use webhooks. Is there a sample CI file?
#jibsonline, You can refer to my answer provided in the below link.
However the script answers only how to break the build on sonar analysis and display the results.
How to integrate Sonar Quality Gates with Gitlab-CI
Since gitlab triggers the build, once the changes were pushed, it is not advisable to set up an automated tool to revert the code changes on your behalf. Whenever a build fails, write script (dependencies) such that the code will not be deployed. Since the code is not deployed, your environment will not be effected. Also,set up an email configuration whenever build fails.

drone.io Not using .drone.yml file of GitHub repo

I have a problem with the CI tool drone. At the Moment I'm using drone.io and with the selft-hosted version I have the same issue. When I try to build my golang test application drone.io always ignores my .drone.yml file.
The GitHub repo is: https://github.com/norbell/dronetest
My .drone.yml file looks like this:
pipeline:
build:
image: golang:1.6
commands:
- go get
- go build
And the settings page of my drone.io project looks like this:
And when I click the build button it shows me that the project was successfully "build":
Obviously does everything but not building my project. I have done everything I found in the documentation but I can't get it working.
When I put go get and go build or go run main.go into the "commands" textarea field of the settings page, drone is suddenly able to build my go application.
I'm not sure what I'm doing wrong, so it would be very nice if someone could help me. :)
https://drone.io/ - doesn't support .drone.yml file, this file supported by https://github.com/drone/drone
If you want to use a .drone.yml you are forced to host drone on your own.

Go CI does not recognize build file for gradle

I have setup GO CI pipeline for continuous integration in my project. I tried to add a project that is built using gradle. I tried a add gradle task for building my application.
While executing build it shows that
FAILURE: Build failed with an exception.
* What went wrong:
Task 'build' not found in root project 'Gradlepipelinejob'.
I tried to add defaultTasks 'clean', 'compile' to the parent build.gradle file. But still the same error exists. Someone pls help me in resolving this issue.
I think 'build' should be in Command section, rather than arguments. Even after that if it doesn't works, try executing build commands in the agent terminal(or any command prompt).This will let you figure out whether the error is in server or agent.
GO CI runs the command in the code checkout directory so please check if your gradle file is present or not in that directory

Triggering post build and passing in branch name from successful build

I've used Google and looked at the Docs but can't find an answer.
I want to trigger another build or a rake script to do some cleaning up of files after a successful build. I currently use Rake to do my build and pass in %teamcity.build.branch% to it.
I would like to know if I can pass the same branch name of the successful build to the triggered build or script. I can then use this to do some tidying up.
Thanks
In addition to finished build trigger, you need to add snapshot dependency, with "Run build on the same agent" option enabled. This way, cleanup will run after each build, on the same agent.
You then will be able to refer to original build's branch name using dependencies parameters:
%dep.<original_bt_id>.teamcity.build.branch%

Resources