Jenkins: Don't run post build actions for child jobs - jenkins

We are using the Parameterized Builds plugin and a matrix combination parameter. So now, when we build this job, we select which of the combinations we want to build and one "child job" is created for each one that is selected.
Each of these jobs runs their build steps and post build actions. However, I have also noticed that the post build actions run for the "parent job" as well.
For example, we have the job configured to post a message to Slack upon success. Now, if I build the job with parameters and select one configuration to build, I will get two Slack notifications. One for the main job and one for the selected configuration.
Example Slack output, note one with the config selected and one without:
| My Jenkins Project » My Job » my config - #51 Success after 1 min 54 sec (Open)
| My Jenkins Project » My Job - #51 Success after 1 min 55 sec (Open)
So my question is, how can I prevent post build actions from running on the main job?
EDIT: Since creating this question I found this GitHub issue on the Slack plugin that describes exactly what I'm seeing. So it looks like this functionality should be up to the plugins and that a new version caused a regression in this particular plugin.
Perhaps the question is better suited as: Is it a plugin's responsibility to determine whether it is running in the global job or in a configuration job as part of a multi-configuration project?

Whether a message should be posted on Slack for only the child jobs or the parent job also should be part of the configuration that the plugin provides. Here's an example from your github link. The hipchat plugin gets this right:
A similar option from the Slack plugin would solve your problem, there seems to be a PR here to fix it. You can revert back to an older version (<= 2.0) to solve this meanwhile.

Related

Jenkins: How to keep specific builds longer?

I have a declarative pipeline that executes almost regularly.
Upon specific condition (evaluated during the job run) I'd like to keep the job longer than usual.
Usual runs I keep for one week.
If condition 1 is true I want to keep the build for up to a month.
If condition 2 is true, I want to keep the build for up to six months.
Can Jenkins do something like that out of the box, or can it do it by adding some plugin?
So I found a solution to this job: Jenkins out of the box cannot do what I was searching for. However Jenkins can run plugins. Not finding any plugin that would satisfy my need I started creating my own. Here are the highlevel steps if someone wanted to do the same:
follow the Jenkins Plugin development tutorial. From that you have a plugin with a build step and a build action
modify the build action to store the information about the two conditions, or even better the resulting keep period.
modify the build step so the information can be set from freestyle builds or pipeline steps.
create a BuildDiscarder that reads the information from the action and honors it before triggering a delete

Trigger a downstream project on demand

Given the following situation
main-job builds and tests a project
installer-job copies artifacts from main-job, and packages them into an installer
installer-job is set as downstream project of main-job via Parameterized Trigger Plugin.
But the installer-job should only be triggered on-demand from main-job's build page.
It's possible to trigger the downstream job on the project page:
But it doesn't seem possible to trigger the build from a specific build page.
Is there any option to get such a trigger button on the build page?
Note: It's a freestyle project, not a pipeline one. So things like the Build Pipeline plugin don't help, unfortunately.
An elegant solution is possible via the Promoted Builds Plugin. "Promotion" is some activity that's performed when a build fulfills certain criteria, like
build was successful
all downstream builds passed
explicit, interactive confirmation
In your case, this condition will be simple: just "main-job" needs be successful, and you will want to confirm explicitly.
There's lots of possible steps that can be triggered as promotion activity -- what you want is to trigger a build of the "installer-job", which can be configured easily.
To summarize, for "main-job", you will configure something like this:
When you do that, the 'main-job" builds will feature a "Promotion Status" button. After pressing the "Approve" button there, the promotion will be enabled and the "install-job" will start building:

Jenkins executing one job that runs multiple jobs

i am new to Jenkins , i need to execute one job that run's another multiple jobs in parallel were it should not stop even if one job fails.
i am not sure how to achieve it. After googling i can achieve by 3 ways Multi-Job plugin , Pipeline multiple Jenkins jobs , Build after other projects , Build Flow Plugin.
can any body please provide me the correct way.
Update : i am trying to achieve this using the pipeline plugin , can any body suggest me were it was correct choice ?..Please suggest!..
We use the Parameterized Trigger Plugin to do this.
In your build configuration add a Trigger/call builds on other projects build step. Add the names of the builds you want to trigger as a comma separated list and make sure that the Block until triggered projects finish their builds box is unchecked. Your build will trigger each of the listed builds, however note that your parent build won't wait for them to finish it will just trigger them and then perform the rest of it's buildsteps so if you have buildsteps.
If you do want to wait then check the block until triggered builds finish box, but set the options for when to fail the build, build step or mark the build as unstable appropriately.
If you need to pass parameters to the jobs you can add parameters using this plugin. If your downstream jobs need different parameters for different jobs you can click the add trigger button which adds another project to build where you can specify different options.
If these other jobs are follow up jobs to the current job and you don't need to wait for them to finish you can also achieve what you want to do by using the post build action build other projects, but again this occurs after the current job and you won't be able to use the results.
can any body please provide me the correct way.
I wouldn't approach using Jenkins with a "one correct way" mentality. Often times the requirements of your build will dictate which method or plugin you use in your build configurations.
The job can start other jobs via the jenkins api.
updated Answer : i used pipeline plugin to achieve my task and tuffwer was right to if u have paramaterized trigger plugin!..

Build daily with Jenkins Multibranch Pipeline [duplicate]

This question already has answers here:
"Build Periodically" with a Multi-branch Pipeline in Jenkins
(6 answers)
Closed 6 years ago.
I created a GitHub Organization project on Jenkins. This scans my GitHub profile and sets up a Multibranch Pipeline (if I understood correctly). In the end I have a bunch of projects which are executed by the respective Jenkinsfiles. If I push something to GitHub or open new Pull Requests, Jenkins gets triggered and everything works as expected.
Unfortunately there is no way of configuring these Projects and I have a project which I want to build daily, regardless of changes on GitHub. Is there a way to trigger a single project daily? I am also fine with building every project daily.
Sorry, if I missed some information or said something wrong. Jenkins and its plugins are very hard to understand for me, at the moment. Please ask if something is unclear.
If you look at your Multibrach Pipeline then you will see a button Configure at the left side. If you click on there you get to the configuration of the project.
Note: If you do not see the button it is possible that you do not have sufficient permissions.
Once you are inside the configuration, there is a section called "build triggers" where you can check a checkbox to start the build time based/periodically.
Inside there you will have to add a so called cron expression.
Example:
H 7 * * * to start a build daily at 7AM.
Edit:
If you are not able to edit the configuration of a certain job it might be possible that you create a periodially scheduled Multijob Project that triggers a build on your original job.

Jenkins Job Current "Log Status"

I've got a job that runs for a long time (for example, it builds few solutions), Is there a way to know the current solution that is beind compiled on runtine?
I mean, the Log is very long, so sometimes is confusing to know what is the current compilation that is running.
I want to know what is the current solution that is being compiled now...
Any plugin or a way to do that?
It would be easier to diagnose problems if you split the job into multiple jobs (each one building a single solution). If you have dependencies between the different builds (i.e. one part of the build cannot happen until another part has completed), you can create a build pipeline, where once one job finishes, it triggers the next job in the pipeline. You can do this using the post-build action Build other projects in the job configuration.
There is also an excellent build pipeline plugin which helps you visualize your build pipeline.
If it is the case that you must have the whole solution built in a single job, then one approach would be to use the Jenkins log parser plugin to display a cut-down version of your build log, which just highlights the key events you are interested in to diagnose such problems.
More details of this plugin can be found at:
https://wiki.jenkins-ci.org/display/JENKINS/Log+Parser+Plugin
I've got two ideas for a possible solution but they needed to be implemented:
1. Adding a prefix for each row in the Log. The prefix could be a string.
for example, if there was a new Project Compilation started then the Log finds the line
----- Rebuild All started: Project: PROJ1 , Configuration: Release x64 ------
Then it adds all the rows after it the prefix "Building PROJ1"
until the log reads the next project:
----- Rebuild All started: Project: PROJ2 , Configuration: Release x64 ------
2. Adding a the current project name that's building to the flashing Job status blue ball.
I mean, finding the current building project from the Log, then adding it next to the current job status (the flickering ball).

Resources