Set web-hook event for gerrit submit event for specific project - gerrit

I want to set post submit event for gerrit that check the commit message
Currently I defined a lambda function that triggered by api, I tried to set on project configuration the trigger as followed:
[remote "changemerged"]
url = http://<webhook-api>:8081/change-merged
event = change-merged
Based on that answer but seems this is not the way

Related

Catch the event of removing a branch from github webhook

I need to make my own script to remove the branch on the removal event from the Github. I use multibranch pipeline and Blue Ocean plugin.
I'm assuming you already have webhooks set up for push events. You will need to set up a similar webhook, but instead of using the push hook, use a delete hook, which is fired any time a branch or tag is deleted.

How to trigger job when a new patchset is uploaded for an existing change

My job works well when the patchset is uploaded for first time. After that when a new patchset is again uploaded on the same gerrit change, it does not trigger again. I already tried the Trigger On Comment Added Contains Regular Expression. I have these Trigger On currently in the same job:
Patchset Create
Comment Added Contains Regular Expression
You just need to use "Patchset Created" on "Trigger on" item in the Gerrit Trigger configuration options:

jenkins: Find the triggering user of a job for the build-script

We're using Jenkins and Slack.
I'm trying to setup a slack notification about a build, and I would like the notifucation to include more information - so I resort to the custom message.
I found about $GIT_BRANCH and $BUILD_NUMBER and $JOB_NAME and other interesting guys, and put them to use.
But I lack a way to mention the cause that triggered the build - be it a polling on the scm, or a user that pressed build now.
The later is of extreme importance - especially in jobs that deploy to a target environment...
Can anybody recommend me a way to detect the triggering cause and add it to the custom message?
BTW - I'd want this information not only for slack notification.
I'd like to add this information to a signature file that we add to every artifact (as well as other things)
Use the Build User Vars Plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin
You will have the variables:
BUILD_USER – full name of user started build,
BUILD_USER_FIRST_NAME – first name of user started build,
BUILD_USER_LAST_NAME – last name of user started build,
BUILD_USER_ID – id of user started build.
*If you want to get it from other job you can use the below URL:
http://[jenkins-server]/job/[job-name]/[build-number]/api/xml?xpath=(//action/cause/shortDescription)
It will directly return the line:
< shortDescription>Started by user foobar< /shortDescription>

Is there a way to inform users about a change in Stash repository?

I would like to know if it is possible to send an e-mail notification to certain users when there is a modification to a particular directory within a repository in Stash. I know it is possible to write a shell script within Jenkins project to do this and then inform through e-mail but I would like to know if there is a native option within Jenkins configuration to this action.
This is possible within BitBucket Server itself as of May 7, 2013:
Repository subscriptions
[...] At times, you may want to receive emails on specific types of messages you care most about including:
...
Commits – when a new commit is added or a comment is left
...
See also Manage Inbox and email notifications.
You can use Poll SCM under Build Triggers section.
Define a job that uses GIT plugin, specify a workspace and machine so it'll always be synced with the latest, and poll every 2 minutes. if there is a change in the repository the job will be triggered. Add a post build action to send emails using the built in email notification or using Email-ext plugin.
Don't forget to edit the SMTP information under Manage Jenkins->Configure.
You can check Here for more information about Jenkins Polling.

How to trigger a Jenkins job from a status change in Jira

I have been looking for a while now for a way to trigger a Jenkins job from the status or a ticket/story in Jira changing status. To give a more detailed example when my team moves a ticket to the 'ready for test' column we would like to be able to trigger a sanity test pack in Jenkins, the ideal situation would then be that we are able to post the results (generated as a html) as a comment on the ticket within Jira. Failing that we would like to be able to publish the results as simply pass/fail.
I have recently been looking at the Jenkins Jira plugin but this does not seem to have the functionality to work both ways, in other words it can post results after a job has run but you cannot trigger the job from a change of status in Jira. Is there any such plugin available or is it something that we will need to create ourselves?
Cheers in advance
So, basicly there are webhooks in jira (https://developer.atlassian.com/jiradev/jira-architecture/webhooks). With it you can configure it to trigger specific url on issue status change. The specific url should be jenkins API, for example for triggering a build you should call an external url like (if you are building with parameters): http://server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value
Some more info https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
I have written a Jenkins plugin that supports JIRA status change trigger: jira-trigger-plugin.
This plugin also injects an environment variable of JIRA_ISSUE_KEY, so you can utilise this information to publish your result back to JIRA e.g. using REST API.
Please follow as mentioned below:
GIT:
You can set the web hooks for git/ bitbucket /stash on commit which inturn should change the state of task in JIRA.
JIRA:
Once you in JIRA. define the workflow for your task.
In this particular workflow you can set a post-function where the web hook should be configured. In this configuration of webhook in events define JQL as below:
status CHANGED FROM "To Do" TO "ready to test".
In the same mention the job that needs to be fired in the URL section.
You can look through webhooks in Jira :
https://support.atlassian.com/jira-cloud-administration/docs/manage-webhooks/
You also need to add the Generic Webhook Trigger plugin to your Jenkins :
https://plugins.jenkins.io/generic-webhook-trigger/
You can find here an example on how to use the Generic Webhook Trigger plugin with Bitbucket Github and Gitlab. https://github.com/jenkinsci/generic-webhook-trigger-plugin/tree/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd
It involved multiple steps
If you are using Git/Stash/BitBucket (which i implemented),
You can simply
configure the commit hooks in your Stash/Bitbucket
Attach events to your JIRA workflow
Jenkins JOB - post build events - configure Notify
Stash plugin Set the Poll SCM
That's it

Resources