How can I persist Jenkins status page? - jenkins

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.

Related

Need proper looking e-mail notification from Jenkins: including SVN changes made since last build and errors during buil, if any

Jenkins is used to poll SCM (SVN) using SVN plugin, then build using Ant/Maven/Gradle
In Post Build Actions, I`ve chosen Editable Email Notification, and under section of Triggers chose Always
And in Content section I have set the following tags (as is):
$PROJECT_DEFAULT_CONTENT
$CAUSE
$BUILD_LOG_REGEX
$CHANGES
Unfortunately it does not do what I want. First two is fine, but last two, I need them to send errors and warnings (only, not all the log), and what changes and in what particular files were made since last build.
Thank you.
Ok, no one answered, but I find solution for changes on my own:
${CHANGES, showPaths=true, format="%a: %r %p \n--\"%m\"", pathFormat="\n\t- %p"}
As for $BUILD_LOG_REGEX, now when I know format, I`ll find solution too some time later.

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 - Change context on Set Build Status on GitHub Commit

In a regular free style job, I would like to set the build status on every GitHub commit (pending, success, & failure). This is really easy to do with the GitHub plugin. The only catch is that I want to change the context being sent to GitHub. By default, the plugin sends the full project name ('/folder/subfolder/job-name-foo') or the display name if configured in the advanced project properties.
I want the context to be 'continuous-integration/unit-tests' for my unit test jobs and 'continous-integration/style-checks' for the style check jobs. I can't change the display name in all of my jobs to those values because I would have a ton of conflicts. I have several hundred jobs.
I've found a merged PR that adds the functionality to set a custom context, but I can't figure out how to use it!! https://github.com/jenkinsci/github-plugin/pull/100
It uses the token macro plugin which I've never had to explicitly use https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin but I understand how to use it. The problem is that I can't find the right token to overwrite the GitHub context.
So far I've tried:
${displayName='Foo'}
${displayName,foo}
${displayName,var=foo}
foo
I've tried about a dozen or more combinations. Anyone else set a custom context?
This plugin provides a build step to set commit status with different contexts: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Integration+Plugin
You can invoke this step with different commit contexts at different stages of build.

hudson: way to get the user value who initiated the build?

Is there a way to get the hudson job initiated user name.
Is it possible to get using script shell, py etc.
Lets assume I have the build # which was initiated. I know how to get the latest build info using api but would like to get a user details for a specific job.
Do you think, this will work for hudson? :)
https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin
Thanks in advance
That plugin will not work with Hudson, unless you download a very old version of the plugin. I'm not sure how many people are still using Hudson and haven't upgraded to Jenkins.
Anyway, when a user manually triggers a build, this is called a "user cause"; there are other types of cause, e.g. SCM trigger.
You can use the JSON or XML API to get the causes for a build, for example:
https://ci.jenkins-ci.org/job/remoting/lastSuccessfulBuild/api/xml?xpath=//action/cause/userId
In this case, this returns the username that caused the build to run.
Though note that there may be multiple causes for a build, and potentially other cause types that use the userId field.
This works in Jenkins, but it should also work in Hudson, but I haven't tested it.

Jenkins + Gerrit Trigger Not Automatically Building

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.

Resources