How Can I trigger a jenkins job after successful completion of another job and both the jobs are running in different Jenkins server - jenkins

I need to trigger a job in server1 after the successful completion of a job in Server2. Both the servers are under same domain.

Please have a look to the URLTrigger plugin for Jenkins.
Install this plugin on the server1.
On your server1/job, please configure the build trigger like below:
When the job will be completed on the server2, the server1/job will see a change on the buildNumber attribute.
It will trigger a new build on server1.

If you have a jenkins master, you could add the other servers as jenkins slaves and use the node('[slave name]') { ... } feature of the workflow plug in to start a build on that slave.

Related

Kubernetes Cron Job to trigger a Jenkins pipeline

My team to to create a cron in Kubernetes/OpenShift that will trigger our Jenkins pipeline that we have set up. We tried doing the triggers{} syntax and the build periodically option on the Jenkins UI, however these are unreliable for us since whenever Jenkins restarts, those build triggers on Jenkins get removed.
There is two approaches you could use here:
Make your Jenkins stateless with the Configuration as Code plugin
Use a curlimages/curl container to trigger a job via the Jenkins REST API

Ephemeral Jenkins Pipeline Jobs from Github and Jenkinsfile

I have automated Jenkins master and slaves deployment and redeployment successfully.
I know how to manually create pipeline jobs and add github repos to use their Jenkinsfiles for the steps.
my issue is how can I automate the pipeline jobs addition to jenkins after its been destroyed and redeployed without having to manually create the pipeline jobs and point to Jenkinsfile each time.
I have seen this done before in a container environment with chef and docker when redeployed or updated it re-adds all the pipelines automatically again.
I want to not use the UI at all only to confirm job status progress and verify settings.
I would recommend looking at the JobDSL Plugin to create jobs, using a seed job to create them on initial Jenkins startup. The Jenkins Configuration-as-Code plugin can be used to setup any other configuration outside the jobs.

How to trigger jenkins job that execute automation test scripts when code is pushed in development server?

I am new to Jenkins. I have development code repository at bitbucket and another test script code repository at bitbucket. Now I have setup a Jenkins job by linking test code repository. Is there any way to trigger a build when code is pushed in develop repo?
I tried many times by pushing change in develop repo, but it does not triggers the jenkins job.
You can configure the Jenkins trigger as an SCM poll.
You will have to enter a cron expression for the polling time period, like:
*/5 * * * *
This means polling from 5 to 5 minutes. If any change is detected, then the build is triggered.
You can add the BitBucket Plugin to your Jenkins instance. It will allow you to configure a webhook in BitBucket that will then trigger any Jenkins job listening for that webhook. The plugin's page has a detailed breakdown, but the basics are;
In your repo in BitBucket, create a new Webhook using your Jenkins' url. I believe the url is generally http://[your jenkins url]/bitbucket-hook/
Make the trigger a repo push.
In your Jenkins job, check the box "Build when a change is pushed to BitBucket" under the Build Triggers section.
Now any time you commit to the repo you created the Webhook on, that Jenkins job will be run.
You can also limit what branches trigger commits by parameterizing your Jenkins build to ignore certain branches / keywords / etc if that's something you need for your specific project.
You can use webhooks to trigger build automatically. There are few options how to use it. See the following articles: this, this and this.

how to trigger Jenkins job from ant script running on same Jenkins server

I'm running an ant job that runs several thing on master node and need to trigger several jobs on slave servers based on the options i select from the main job parameters
is there a way to call another job from within ant script without using jenkins-cli.jar as external command
You can trigger Jenkins jobs by doing an HTTP request:
Go to your Job Configuration
Build triggers > Check 'Trigger Builds Remotely' and think of an access token, e.g. SOME_SECURE_TOKEN.
In your ant script: execute a POST request to JENKINS_URL/job/JOB_NAME/build?token=SOME_SECURE_TOKEN
Note that if you have authentication in place, you need to set up a user who is authorized to start the other jobs. In that case read this more detailed explanation: https://www.nczonline.net/blog/2015/10/triggering-jenkins-builds-by-url/
Another solution would be to use the Parameterized Trigger Plugin to trigger builds from a Jenkins step. You mention that the jobs that need to be triggered may depend on the job parameters. In that case you can combine the Conditional Buildstep plugin with the Parameterized Trigger plugin.

Jenkins handle node disruptions

How can I get Jenkins to handle node connection failures?
Right now, if a slave drops the connection to the master, all the builds running on that node fail. Ideally, these would just be rescheduled.
Has someone already addressed this issue?
Do I need to write my own plugin for this? If so, where would I "extend" Jenkins functionality?
See the Post build task plugin:
This plugin allows the user to execute a shell/batch task depending on the build log output.
See http://<Your Jenkins>/job/<Your job's name>/api/:
Perform a build
To programmatically schedule a new build, post to this URL [http://<Your Jenkins>/job/<Your job's name>/build]

Resources