Jenkins Script: Trigger using Shell not working - jenkins

I am using Jenkins script polling.
[ScriptTrigger] - Poll with a shell or batch script IS CHECKED
script value is
#!/bin/ksh
return 0
Exit Code PARAMETER IS 0
polling Schedule is * * * * *
The polling is never happening and the build run only if i schedule a build manually .
What am i doing wrong? What should i change?
The script trigger log is
[ScriptTrigger] - Poll with a shell or batch script
Polling has not run yet.

Related

Jenkins Pipeline Continiously

How to run Jenkins pipeline continuously?
The pipeline is started and once it's finished it runs again and so on
I tried */1 * * * * to run every minute but it's not waiting until the previous pipeline is finished but I need to wait until finished and only after it start running it again
You can disableConcurrentBuilds() in your pipeline. This will prevent it to run till the previous ones complete.
Why not trigger a new run of the pipeline as a last step (or a post step depending on a condition if you need to) of this same pipeline?
See the build step to do so: https://www.jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job

Unable to run multiple instances of the same Jenkins job using cron

I have a plain Jenkins job.
The job is restricted to run on a single node using label.
The node and the job settings are set to execute in parallel.
I use "parameterized scheduler" plugin to run 4 instances of this job in parallel every 30 minutes like shown below:
*/30 * * * * %app=myapp1
*/30 * * * * %app=myapp2
*/30 * * * * %app=myapp3
*/30 * * * * %app=myapp4
As you can see the parameter(app=) is different for each run.
However, only one instance of this job runs tree first one i.e app=myapp1
Can you please suggest what needs to be done to fix the problem.
Note: when i change the cron time to */30, */31, */32, */33 then this works fine. Infact i even see parallel execution of the same job incase the job takes more than a minute to complete.
In summary my issue is about running multiple instances of the same job in parallel using cron and not a manual trigger.
With manual trigger i m able to have multiple instances running in parallel.

Jenkinsfile | Declarative pipeline | Run a Job after some specified time (in background)

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

Jenkins post build step is delayed for a couple of minutes

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)

Can Jenkins return 0 and 1 after test suites completed?

My query is related to Jenkins server.
I have made one API to hit the Jenkins server where Jenkins starts test suites.
My question is: can Jenkins server return 0 if any test case fail, and 1 otherwise?
The API URL is in the form
JENKINS_URL/job/Encore_Automation/build?token=TOKEN_NAME
By looking at Build Triggers / Trigger builds remotely (e.g., from scripts) it seems like this option only supports queuing a project and it does not let you retrieve results.
Jenkins REST API
After build has been triggered from REST API call, you could start making consecutive REST API calls to check it status.
Jenkins CLI
However Jenkins offers a jenkins-cli tool which let you not only to trigger the build but also to wait until its completion:
java -jar jenkins-cli.jar -s http://localhost:8080/ build JOB [-c] [-f] [-p] [-r N] [-s] [-v] [-w]
Starts a build, and optionally waits for a completion.
Aside from general scripting use, this command can be
used to invoke another job from within a build of one job.
With the -s option, this command changes the exit code based on
the outcome of the build (exit code 0 indicates a success)
and interrupting the command will interrupt the job.
With the -f option, this command changes the exit code based on
the outcome of the build (exit code 0 indicates a success)
however, unlike -s, interrupting the command will not interrupt
the job (exit code 125 indicates the command was interrupted).
With the -c option, a build will only run if there has been
an SCM change.
JOB : Name of the job to build
-c : Check for SCM changes before starting the build, and if there's no
change, exit without doing a build
-f : Follow the build progress. Like -s only interrupts are not passed
through to the build.
-p : Specify the build parameters in the key=value format.
-s : Wait until the completion/abortion of the command. Interrupts are passed
through to the build.
-v : Prints out the console output of the build. Use with -s
-w : Wait until the start of the command

Resources