Is there an easy way in Jenkins to list all all builds marked as keep-forever? And then, ideally, one click to either unmark the build as keep-forever or to immediately delete it?
In our process, we mark a build as keep-forever if it involves some specific type of failure; that's to keep Jenkins from automatically deleting over time. I need an easy way to get a list of all those keep-forever builds so they don't take up all our disk space over time.
The following XPath query against Jenkins will list the URLs of all builds marked 'Keep Forever':
http://[jenkins_server]/api/xml?depth=2&xpath=/hudson/job/build[keepLog="true"]/url&wrapper=forever
Enter it in the browser and see what it returns.
Now, you can embed it into XSLT-based HTML to get a list with links to those builds. To delete the build you can provide a button that invokes Jenkins CLI:
java -jar jenkins-cli.jar -s http://[jenkins_server]/ delete-builds [job-name] [build-num]
Unfortunately, I do not know how to disable 'keep build forever' with CLI without deleting it.
I was looking for the same thing, and our jenkins is pretty big as well and trying the link:
http://[jenkins_server]/api/xml?depth=2&xpath=/hudson/job/build[keepLog="true"]/url&wrapper=forever
I ended up crashing it.
But as it turns out I only require the last 'keep forever' build of one job at a time, which seems to work way faster. So I use the following instead:
http://[jenkisn_server]/job/[job_name]/api/xml/?depth=2&xpath=/freeStyleProject/build[keepLog="true"]/number&wrapper=forever
which returns the xml with all the numbers of build that are marked as 'keep forever'
You can modify the xpath to fit your needs.
Related
I setup my jmeter to run on jenkins daily. Everything works fine except the past jenkins build automatically flip to fail status the next day when a new schedule run kicks in and it also removed the past build results. I attached a screenshot of the build history. For sep 12, they were all green.
Anyone experience this issue or know which area I can look into?
My goal is to try to compare with past build result and send an email if the performance didn't pass criteria.
I am happy to share more details.
Unfortunately we're not telepathic enough to guess the reason by looking at a single screenshot.
Double check your job configuration, especially location of the JMeter's jtl result files as it might be the case you're storing them in current job folder instead of workspace
Double check your Performance Plugin configuration, especially "thresholds" section
Inspect Console Output for the previous/latest builds
Check jenkins.log file for any suspicious entries
I have a significant set of Groovy pipeline scripts for our Jenkins build process. I am in the process of moving those scripts onto another instances, and would like to replicate the set of approved scripts that were not originally white listed.
Is it possible to export the list of approved signatures and import them into another instance?
The only other solution I have is to constantly run and rerun the scripts and approving each signature as it breaks the build. Since the scripts are quite complex, and not every run is guaranteed to hit each line, this is not going to be a quick process.
The other option would be to create a master 'white list' script which runs all the currently non-approved scripts again and again until all instances had been approved.
Neither of these options is great, so I'm hoping for a simple import/export to avoid having to do this work altogether, but I certainly can't see an option available to be in the UI.
Cheers
I do not believe there is import/export functionality by default but maybe there's a plugin that'll do it.
If you have access to the directory Jenkins' is installed or runs in you should be able to find the scriptApproval.xml file.
If you explore that you'll find approvedScriptHashes and approvedSignatures etc. You can lift this file entirely and paste it in the new instance or copy across the specifics you need (either way you'll need a restart).
Looks like there's an open request for this sort of functionality here
I want to have Jenkins CI test every branch but not all existing one, solely the ones which received a recent push.
I have set up a GitHub web hook which triggers new builds. This works fine for the branch specifier set to master. Now I tried ** so every branch is built.
The problem: on the first push it tries to build every branch, which is simply too much and would take ages. Is there a way to limit this?
There is no configuration which supports the feature you are requested and since it looks like there is no plugin yet. Your best shot would be to implement your own plugin that can specify a certain date threshold for branches.
Having said that, to solve your problem I would simply:
Empty the shell script for your job
Trigger a new build
Set your shell script again
This way all remote branches get checked out, run and marked as successful within no time due to the empty shell script. After re-enabling your actual shell script you are good to go.
Is it possible to set the build result for a build after that build is complete?
I could not find any plugins that do this already, and I was considering writing my own, but I wanted to see if this was even possible before going down that path.
(I have looked at existing code and how the "Fail The Build" plugin works as an example, but my understanding of the Jenkins code base is not advanced enough to understand what all the possibilities are.)
Use case: we have a build pipeline, and near the end of the pipeline there is a deploy-to-qa step that deploys the artifact to a QA environment. We have automated tests before this step to try to catch any problems with the artifact, but our test coverage is not very high in some areas so bugs could still slip through the cracks. I'd like to have the ability to mark a deploy-to-qa build as FAILED after the fact, to denote that that particular pipeline was invalid and is not a candidate for production release. (Basically the same as this Build Pipeline Plugin issue)
After some more investigation in the code, I believe that this is not possible.
From hudson.model.Run:
public void setResult(Result r) {
// state can change only when we are building
assert state==State.BUILDING;
// snip
...
}
So the build result cannot change except when in "building" state.
I could try to muck with the lastSuccessful and lastStable symlinks (as is done with the delete() function in hudson.model.AbstractBuild), but then those would be reset as soon as Jenkins reloaded the build results from jobs/JOBNAME/builds/.
I have an untested suggestion: Make a parametrized build, where the parameter determines if build will fail or not (for example simple bat / shell script testing the parameter from the environment variable it sets, and doing exit 0 or exit 1). This assumes that build pipelines manually triggered step will ask the parameters, and not use default values.
If it does not support interactive build parameters, then some other way is needed to tell this extra build step wether it should fail or not. Maybe editing upstream build description or display name to indicate failure, and then allowing build pipeline to continue to this extra build step, which probably has to use system groovy script to dig out upstream build description or display name.
I have seen several debates on this topic previously, and the outcome was always that it is theoretically possible to do so, but the codebase is not designed to allow this and it would have to be a very hacky workaround.
It's also been said that this is a bad practice in general, although I don't remember what the argument against it was.
I am facing the same requirement. I haven't found an appropriate plugin, changing the build status is not just a flag but has other impacts on links (eg latest successful build etc). So instead of changing the status of the build I looked for a possibility for qualifying the build. The Promoted Builds Plugin apply flags to build to define e.g. different quality stages. Build promotions can be performed manually or based on e.g. downstream project successful builds. Any successful build can be qualified, based on the promotion additional build and post build actions can be executed, e.g tagging or archiving.
Actually I was able to do it by changing the build.xml manually to <result>FAILURE</result>.
I've then played a little bit with mklink to create some symbolic links and also renamed the lastSuccessfulBuild to lastFailedBuild and it worked. If you are allowed to access the filesystem from within a Jenkins PlugIn, then it is possible to write one.
In case you are fine to delete the current build and start the same build using a version number and setting the next BUILD_NUMBER to the deleted one, then you could use this plugin to tell it to fail instead of succeed:
Fail The Build Plugin
I've used the Simple Promote Plugin in Jenkins and it set my build to "keep this build forever".
Is there any way I can delete it?
I got access to the slave who build it and to the master (tried to find anything related in there but no luck).
I'm not sure whether (or how) the Simple Promote Plugin affects this at all, but can't you just click the button that says "Don't keep this build forever", followed by "Delete"?
When a build is marked as "keep forever" (and the padlock icon shows next to the build), you should be able to "unlock" it by pressing that "Don't keep..." button on the build page.
Just as Christopher said, you can remove the build just by deleting the build directory on the master, inside the job directory.
However if you access the page again, the build data gets dumped to disk again. So you either shut down Hudson first, or you go to the Hudson management console and 'Reload Configuration from Disk' which basically discards whatever's in memory and reloads from your config files.
Just make sure you do it right after deleting the folder.
In order to delete builds marked "keep this forever" you should change that flag to opposite state.
Please follow next steps
Open within a text editor $HUDSON_HOME/jobs/job-name/builds/xx/build.xml
Change
<keepLog>true</keepLog> to <keepLog>false</keepLog>
Go to Manage Jenkins -> Reload Configuration from Disk
After these steps you will be able to delete build marked as "keep this forever"
I think that the final (and may be the only one step) to completely delete build from Hudson's history is to modify "nextBuildNumber" file placed in job directory.
Please remember that "Don't keep this build forever" button will only appear when you enable "Discard Old Builds" inside job configuration. I am not sure if it affects Simple Promote Plugin, but it work in this way with 'Release Plugin'.
MichalT
Not sure about masters and slaves, but there is an answer here that allowed me to delete a build "explicitly marked to be kept".
List all keep-forever builds in Jenkins?