Jenkins + Gerrit Trigger Not Automatically Building - jenkins

Jenkins does not seem to be automatically pulling in changes that need to be reviewed from Gerrit.
We're using Gerrit Trigger.
Also If I try to manually trigger some, it seems like nothing ever happens.
The "control" in the Gerrit Trigger management area, doesn't seem to much... flashes either "starting", "stopping" or "restarting"
Any ideas where I went wrong?

I was just having the same problem, and it had to do with the default Gerritt setting in my job for matching branches.
In your job, under Gerritt Trigger, if your Branches Pattern says "**", make sure the Type is set to Path, or else it won't match any branches.

I've actually stumbled over the same problem and it took me a while to figure out the UI, since I thought the branch and project configuration belongs to Dynamic Trigger Configuration. The configuration will basically need to look like this:
Note: my configuration uses the Silent Mode, since I don't want the plug-in to communicate back to gerrit.

Related

Add condition to transition using script runner

I am using the scriptrunner plugin for Jira.
Is it possible to add a condition to a transition using scriptrunner?
Currently, my condition is in a script which I have manually added to the workflow.
But I was wondering if there is a way to do it automatically?
I was looking through documentation on: https://docs.atlassian.com/
I came across this method:
replaceConditionInTransition which is a method of WorkFlowManager.
But I'm unsure on how to use this.
Any help would be appreciated.
Conditions as any another scripts can be added from file system. You can store scripts in any VCS (bitbucket, github, gitlab, etc) and automatically deploy them to Jira server file system through any CI/CD system (teamcity, jenkins, bamboo, gitlab, etc).
So, as result process will be looks like. 1. commit changes in you script to vcs 2. wait a bit for auto deploy (e.g. triggered by commit) 3. done. As additional you can write any script/service/etc for commit these changes automatically if needed.
Also look at script roots it's helpful way which allows reuse any of script fragments through helpers classes.
It's rather conceptual answer basically because implementation is depends on environment, but I hope that you get at least one more point of view to solve this task.
I think that using the Java API to modify Jira workflows is pretty tough. You could dig around in the workflow editor to see how conditions are added there. Remember that you have to do this in a draft workflow and then publish it, which takes some time in large projects
I like the idea of replacing a script file as easier, if it can be done when no issues are transitioning

Updating JIRA issues from gitlab pipeline

I want to move an issue to the deployed stage (transition) when the gitlab pipeline of a merge request has finished. Is that even possible?
My Idea so far:
The pipeline is related to that specific issue by both the branch name (see 1.) of the merge request and also the message of that merge request like so "Finish PV-1234".
I can parse the issue key from the branch name.
I can call a server to run a script making the Jira api call.
If you directly want to close the issu, look into the gitlab jira integration docs - therefore you have to add a description to your MR, to tell the integration to close the issue, as soon as the MR was merged.
If you want more control, write yourself a simple script, that first gets the ids of the available transition (You can get them via /rest/api/3/issue/{issueIdOrKey}/transitions see here) and after that posts the transition you want (You can do that by posting on the same endpoint, as the get command mentioned before see here).
Sad that the jira integration doesn't provide more issue-movement than jsut closing issues...

How to start a build via a phrase in Jenkins Pipelines

I am switching from the github pull request builder plugin (for security reasons) and am trying to get the same functionality from Pipelines (using different plugin). I think I have just about everything, however I can't seem to find a way to re-trigger a build simply by a trigger phrase like in github pull request builder plugin. Is that possible via pipelines?
By trigger phrase, I mean that a user can make a comment on the PR saying "Jenkins re-test" and it will kick off the build again.
You can put a condition at the top of the build script to check for the message. You can access the changesets using currentBuild.ChangeSets. The last changeset is at the end of the array. Then you need to access the last element of that changeset. Finally you can access the message via message property. You can then search for your keyword.
I am doing the opposite (not triggering the build with a phrase) but never tried for pullrequests though.
Another idea is to use the "ignore builds with specific message" property and setting this message to be a regex with look ahead that accepts everything except the keyword. I don't really recall the syntax though :/

Jenkins/Gerrit stream events - job triggered on newly created branch

I am using Jenkins in combination with the Git and Gerrit plugins. I would like to trigger a job on Ref Updated. However, I need to understand if the action behind this event is the creation of a new branch. If it is, then I will execute my shell script, otherwise not.
As far as I understood, this info is available in the Gerrit's event json response, but I do not know how to consume this json object via Jenkins in the first place.
Is there a way to achieve this easily via Jenkins (maybe something in the interface I missed)? Or is there another way to monitor the creation of a new branch while still in the Jenkins/Gerrit plugin environment?
So I just recalled there are a bunch of Gerrit environmental variables which are available to use in the building script,
namely these ones. I will just have to check if GERRIT_OLDREV is equal to 0000000000000000000000000000000000000000 and if so, it would mean the branch is newly created (for reference: here). Here is the picture I attached in full size.

How can I persist Jenkins status page?

I would like to persist the status page of a Jenkins build job's build (the one which contains commits as well as why the build was triggered).
This should happen in order to get a changelog file.
How am I able to do this?
For being a bit more precise, I would like to persist the content which is shown from
<jenkins-build-server-address>/job/<job-identifier>/<build-number>/api/json?pretty=true
as a file. A separate buildstep inside the buildjob which takes care of this, would be perfect!
If I'm understanding your question correctly, this earlier StackOverflow question "Jenkins: how to save changelog for build" may have the answer.

Resources