jenkins NodeLabel Parameter Plugin default - jenkins

I currently have two jobs that will run around about the same time to one another.
I have two slaves setup, so was hoping that if job #1 starts on slave #1, that when job #2 starts, it would see that slave #1 is busy and use slave #2.
I have installed the NodeLabel Parameter Plugin, set the default node to slave #1, and the possible nodes for slave #1 and #2 for each job. I have set node eligibility to "ignore offline nodes" and "run next build only if job succeeds" (only because I wasn't 100% sure what to select).
The problems I am seeing are:
If slave #1 is in use when the second job starts, it says "(pending—Waiting for next available executor on slave#1) [NodeParameterValue: slave#1=slave#2]" instead of starting on slave #2
When I manually build this job, it doesn't select the default node automatically, instead it makes me choose using "build with parameters"
I am guessing I am missing something rather simple, as I presume this must be a common use for this plugin... to dynamically choose a slave based on which one is not in use?

I solved this by making sure the the job that is getting called has the default and possible nodes both set to the same two slaves. (instead of the default being just #1).
Secondly, the job that calls the slaves must set a variable inside a .properties file which the job defines as to which node should be ran. This variable is then read using the 'all nodes for label factory option' in the calling job.
This article was very helpful, but like I say, I used the 'node for label factory' instead of the 'node label parameter' option he recommends: http://www.shaunabram.com/dynamically-set-jenkins-node/

Related

Using text editor for configuring Jenkins job's UI elements

Is it possible to edit/save the code of "Job Configuration" (the structure and order of UI elements) ?
The pipeline job get the pipeline code from git, but this occurs only AFTER the job started. I want to edit the UI of job parameters (BEFORE user press "build")
Its necessary for 2 reasons :
its much easier to cut/paste text lines, than move elements up/down with the mouse.
can be saved and deployed easily on a new Jenkins machine
You can edit the configuration before the job is run to add the initial build parameters. If you then have the build parameters also defined in the pipeline, the parameters will be overwritten with the ones defined in the pipeline.
However, for that first build, if the build parameters defined in the job configuration and the ones in the pipeline match, the build parameter values will be used in that initial run.

Jenkins label not recognised for node

I'm trying to deploy to a node using jenkins, and even though the job recognises the node, when attempting to run the job turns to pending and tries to look through every environment for the node.
I've recently set up a new jenkins job to deploy a spring batch project onto a server. We already have a job for another project to deploy to the same node, so the node is recognised, and when viewing that build it does list three jobs.
However, when trying to run this new job, it attempts to find the node against all of our existing labels (see code below for example output), but doesn't find the actual node it should be running on.
The example I've used is NEW_BATCH_DEPLOYMENT, this is listed with having 3 jobs on the environment, two are new jobs that haven't been run, one is a job that ran just before attempting the batch job and succeeded.
For debugging, we've attempted to deploy with NEW_BATCH_DEPLOYMENT_2, which gives us an error for "can't find node with label NEW_BATCH_DEPLOYMENT_2", and if we remove the node name, it simply runs with one of our default nodes.
Has anyone seen something similar to this, or have any idea of a solution? I've compared the new job against the working job and the only differences are the file paths for where to deploy to, and the git url to pull the projects down.
Jenkins version : 2.181
(pending—; ‘Env_1’ doesn’t have label ‘NEW_BATCH_DEPLOYMENT’; ‘Env_2’ doesn’t have label ‘NEW_BATCH_DEPLOYMENT’; ‘Env_2’ doesn’t have label ‘NEW_BATCH_DEPLOYMENT’;
I'd expect it to deploy to the node, but it just hangs with pending and doesn't reach the stage where it would output to the jenkins console.
As mentioned the other job with similar configuration works.
So just to confirm, that is the exact label you are using? "NEW_BATCH_DEPLOYMENT"? Or is that the name of the node? THe Label should be set in the Node configuration, under the "Labels" section, with no extra characters other than the label name.
I've had issues where it can't find the node label if there are spaces in the label (either on the job side or on the configuration/set-up side)
If the labels are correctly set up, it could also be that the node assigned to "NEW_BATCH_DEPLOYMENT" is offline.
Okay, we fixed it.
It seems that on a node level you can set restrictions on jobs, so when the node was set up, it was restricted to only run the one job. The issue is, the only way you can see this is using an admin login.
If anyone else has this issue I'd highly recommending checking the settings on the node to see if the node itself has any restrictions, rather than the job. You will need a Jenkins Admin to do this.

one version number to unite them all

I have multiple build jobs for a project. ie:
projectA is built with different parameters, for SIT, UAT, Staging and Prod DC1, Prod DC2
I use the build ID within the code for cache busting JS and CSS files.
However, there is a little problem here.
I have multiple build IDs for Prod DC1 and DC2.
for example:
DC1: apple.com/me.js?v=45
DC2: apple.com/me.js?v=78
I need one id to unite them all. so that my apple.js?v=blah wont be different in DC1 and DC2. I am also using CDN so this might become a bigger problem.
How can I do this on jenkins?
If all Jobs are connected as Upstream/Downstream way, create a version label parameter in the first Job and pass this label as parameter to the next downstream job till the last Job.
You can use this as the Unique label from starting Job to last Job.
Use Build Name Setter Plugin to set the build name with the unique label for all the Jobs. So that it will be easy to identify the which build belongs to which label.
To have a full visibility of the Jobs use Delivery Pipeline Plugin

Is there a way to resume from a failed job in Jenkins?

I am using 4 Jenkin jobs for Continuous Build and Deployment.The jobs are created for label creation, build using the label, deploy to server1 and deploy to server2 and so on..
The Create_label build will run the MYSQL query in database and get the label. Create_label job on success will invoke the Build-job with the label and upon successful completion of Build-Job, it will invoke Deploy-server1 job and so on..
If the build fails in Build-Job and after that If I start the 1st Create-Label job then it runs the job and creates the NEW label. I mean running the create-label every time will get you incremental label. I can only get the label from 1st job and then pass to 2nd job. Can anyone suggest how to resume from the failed job with out running the first job and start with second job using the old label created(from the last build in 1st job). any work around to accomplish this type of situation in jenkins.
1.Create-Label
2.Build-Job
3.Deploy-server1
4.Deploy-server2
So it seems, you have 2 issue at the moment:
Issue 1 --> If any job fails, the next time it should skip the successful jobs and restart only from the failed job.
Probable Solution --> You could use Build Pipeline plugin, https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin , and if the job fails at say second job, then all you have to do is restart the second job from the pipeline and it would continue from there.
Issue 2 --> For job 2, you not only want to restart it but have to take the input, Label Number, from the previous successful job 1, without restarting job 1
Unfortunately, I don't have a clean automated solution for this. The only thing I can think of requires manual intervention, i.e. since this job is parameterized, change the default value of the parameter to the Label Number from the last successful job 1 before restarting it from plugin(The above plugin doesn't ask for parameters while running the job)
or let Job1 login the label number in some centralized location and let job B take the parameter from there instead of taking it from jobA.
Thanks,
Manish Joshi
I am using MultiJob plugin and you can always just click "Resume build" in the parent job to continue from a failed job.
And in this case the parameters for its execution will be all the same as on those previous run which failed.

can I configure build to happen every minute but deploy should happen only once a day in a single Jenkins job?

In a single Jenkins job, we can trigger a build by specifying a schedule and also by polling. But then, in both the cases, the build is triggered, and the deploy operation that I have configured as a post-build step (using PostBuild Task plugin) also happens. I want that the build happens whenever a change is detected by polling, but deploy should happen only according to the schedule I have provided.
Is it possible to do it in a single job, or do I have to configure 2 separate jobs for them ?
You said you are using PostBuild Task plugin. This allows to do a regular expression on the console log to determine whether to execute a task or not.
Builds started by schedule will have Started by timer at the top of the log. All you need to do is add this expression to your PostBuild step under "Log Text" field. If you are already using some criteria in there, click "Add" button to add another "Log Text" field, and use the "AND" operator between them
It will be cleaner to do it in 2 jobs. However, if you really need to have it in one job, you could use a combination of Jenkins plugins to do the job.
Use EnvInject Plugin to expose the BUILD_CAUSE and/or BUILD_CAUSE_SCHEDULED* environment variable(s). (This may not be necessary, you might be able to reference the Jenkins variables within the Jenkins configuration by default)
Use Flexible Publish plugin, post-build action, to set up a conditional publish step when BUILD_CAUSE == SCHEDULED, or when BUILD_CAUSE_SCHEDULED == true. (Just test one condition.) Note that you'll need to use Jenkins' expression syntax, like so:
${ENV,var="BUILD_CAUSE_SCHEDULED"}
* BUILD_CAUSE_SCHEDULED is not its real name, you'll need to find this out on your own, sorry.

Resources