I have a jenkins job, that gets't delayed before executing postbuild action.
Any ideas what to check or how to proceed? 150 seconds of wasted time is a little bit too much.
Jenkins console output looks like this (see the time difference between first and second line):
14:06:01 [EnvInject] - Variables injected successfully.
14:08:37 Performing Post build task...
14:08:37 Logical operation result is FALSE
14:08:37 Skipping script : echo Testing time
Job configuration:
Build section
Inject environment variables (last task in this section)
Post-build Actions
- Post build task (first task with script: echo Testing time)
Related
My jenkins job "Build" configuration has
3 Execute shell - build tasks
2 Post build action
Is there any way to get the runtime of each buildtask and postbuild action ?
Not directly, which is why:
I use a Jenkins plugin timestamper to add the timestamps in the logs, giving me the opportunity to extract each task duration.
there are plugins like additional-metrics-plugin or build-metrics which collect job duration (but not necessarily task or post-build task duration): they could be good starting point for making a custom plugin which would collect what you need.
I have a requirement to run a destroy job (which will destroy the instances) after testing. The testing will take around 1hr. So the instances can be destroyed after that, adding some leisure time, say after 2hrs.
Jenkins file
Run job-1
Run job-2 - deploy in lower environment
Run job-3 - destroy lower environment after 2hrs of current-time
Run job-4
Run job-5 - after 3hrs
All the jobs should run one after another without wait. And there I am stuck !!
timer - will wait until the given time completes and abort :(
sleep - will wait until the given time and runs next job/whatever :(
trigger - will trigger the job but with cron functionality :(
I am ok to use trigger if my requirement can be accomplished with it.
Or any groovy code to set trigger time (set cron time [currentTime + 3hrs])!
Or
simply - I want to run a cronjob ONLY for one time [just after 3hrs of Now]
Note: I am a newbee to groovy
Use Quiet period set to 120 mins for the last job - Job-5
Groovy syntax is build job: 'Job-5',quietPeriod: 120, wait: false
I've in jenkins a flow like this:
Wrapper Job1
Trigger Job2
(Conditionally) if the job 2 is unstable it triggers the Job3
Below you can see JOB1 (wrapper) configuration pics:
JOB2 trigger configuration :
JOB3 conditional trigger configuration
Now, to give you a little bit of context:
I'm running tests with selenium and cucumber, these tests can randomly fail and if they fail, the job2 is marked unstable (if not the wrapper just finish with success status), in case the job2 fails will be triggered the job3, this is a "RERUN FAILED TESTS" task, then obviously in the case this last will be completed with success I want the wrapper to be marked as SUCCESS.
This should be really easy, but it's not working, below the wrapper (JOB1) jenkins job log:
FIRST STEP (JOB2) UNSTABLE BECAUSE SOME TESTS FAILED:
Waiting for the completion of REM_Parallel_Tag_Sub_Runner
REM_Parallel_Tag_Sub_Runner #9 completed. Result was UNSTABLE
Build step 'Trigger/call builds on other projects' changed build result
to **UNSTABLE**
IF THE JOB2 IS UNSTABLE THE WRAPPER TRIGGER THE JOB 3:
[Current build status] check if current [UNSTABLE] is worse or equals then
[UNSTABLE] and better or equals then [UNSTABLE]
Run condition [Current build status] enabling perform for step [BuilderChain]
Waiting for the completion of REM_Parallel_Sub_ReRuns
THE JOB 3 SUCCEEDED, THIS MEANT THAT THE TESTS THAT WERE FAILING NOW ARE SUCCEEDING, AND I WANT THAT THIS STEP UPDATE THE JOB1 FROM UNSTABLE TO SUCCESS, IT SHOULD BE A NORMAL BEHAVIOUR
REM_Parallel_Sub_ReRuns #6 completed. Result was SUCCESS
[CucumberReportPublisher] Compiling Cucumber Html Reports ...
[CucumberReportPublisher] Copying all json files from: /PATH/workspace /TiaCukes to reports directory: /PATH/cucumber-html-reports
[CucumberReportPublisher] there were no json results found in: /u01/app/build/jenkins/jobs/REM_Parallel_Tag_Runner_Orchestrator/builds/9/cucumber-html-reports
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
No emails were triggered.
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: UNSTABLE
AS YOU CAN SEE THE BUILD STATUS HAS NOT BEEN UPDATED, EVEN IF THE LAST TRIGGERED STEP SUCCEEDED, THE BUILD STATUS REMAINS UNSTABLE
How can i fix it? Should not be so hard goal to accomplish!
Thanks a lot!
Resolved with the use of variables set by Parameterized Trigger Plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin
Pics below:
JOB2 trigger configuration:
JOB3 conditional trigger configuration:
Feel free to ask about details
I have one pipeline build called, for example UAT. This build is scheduled every 3 minutes. And another build called DEV. DEV is scheduled every minute. The task is: to run UAT only if the last DEV execution was SUCCESS. If not - skip the execution. And run it after other 3 minutes with the same condition.
How can I achieve that ?
Don't schedule your UAT job as a separate job but instead trigger the launch once your first DEV pipeline finishes with success.
As you are using pipelines you actually have 2 solutions :
1)
Don't call another job but just call a Groovy function to integrate the DEV part, such as :
node() {
stage "UAT"
// Your existing UAT pipeline content here
stage "DEV"
git 'http://urlToYourGit/projectContainingYourDevScript'
pipeline = load 'functions.groovy'
pipeline.dev()
}
2) Just call a second Jenkins job with this kind of line :
node() {
stage "UAT"
// Your existing UAT pipeline content here
build job: "dev-job"
}
With these 2 solutions you can configure your first job to run every minute and it will trigger the second part/job only if the first one finishes with success (otherwise Jenkins will just fail the build as it would normally do).
I have 2 jobs 'job1' and 'job2'. I will be triggering 'job2' from 'job1'. I need to get the console output of the 'job1' build which triggered 'job2' and want to process it in 'job2'.
The difficult part is to find out the build number of the upstream job (job1) that triggered the downstream job (job2). Once you have it, you can access the console log, e.g. via ${BUILD_URL}consoleOutput, as pointed out by ivoruJavaBoy.
How can a downstream build determine by what job and build number it has been triggered? This is surprisingly difficult in Jenkins:
Solution A ("explicit" approach): use the Parameterized Trigger Plugin to "manually" pass a build number parameter from job1 to job2. Apart from the administrational overhead, there is one bigger drawback with that approach: job1 and job2 will no longer run asynchronously; there will be exactly one run of job2 for each run of job1. If job2 is slower than job1, then you need to plan your resources to avoid builds of job2 piling up in the queue.
So, some solution "B" will be better, where you extract the implicit upstream information from Jenkins' internal data. You can use Groovy for that; a simpler approch may be to use the Job Exporter Plugin in job2. That plugin will create a "properties" (text) file in the workspace of a job2 build. That file contains two entries that contain exactly the information that you're looking for:
build.upstream.number Number of upstream job that triggered this job. Only filled if the build was triggered by an upstream project.
build.upstream.project Upstream project that triggered this job.
Read that file, then use the information to read the console log via the URL above.
You can use the Post Build Task plugin, then you can get the console output with a wget command:
wget -O console-output.log ${BUILD_URL}consoleOutput