github webhook to trigger job on multiple jenkins server - jenkins

My scenario:
Single github repo
4 files in the repo
4 jenkins server
Desired outcome:
pushing changes in file A, should trigger job in jenkins server A, pushing changes in file B, should trigger job in jenkins server B and so on.
Is there any solution for this?

Depending where your repository is hosted (github, gitlab, bitbucket) you might be able to use a pipeline within the repository to look for the changed files and trigger a webhook on the correct server accordingly.
Another approach could be to always trigger a special job on server A which then looks for changed files and triggers the correct job on the right server.

Related

Jenkins does not run the building process after a push

I have the following initial situation:
I have a Docker container running Jenkins 2.379
This Jenkins has the Bitbucket Server Integration and the Bitbucket Branch Sourch Plugin installed
The connection to the Bitbucket server seems to work
I also set up a multibranch pipeline that listens to the repository in the connected Bitbucket server instance
And I have set the Scan Multibranch Pipeline Trigger to All pushes.
Finally, it seems that Jenkins has correctly implemented the webhook in the corresponding Bitbucket project.
Changes to some configurations of the multibranch pipeline trigger the scan process, which works properly. If there are changes in the code of the corresponding branch during a push, the build is triggered.
Clicking the "Scan Multibranch Pipeline Now" button has the same result.
But if I just push some code changes into a branch, nothing happens. My pipeline does not start automatically and no build process is started with the changes made.
Goal: Every push a developer does in a branch of this project should trigger the scan for new branches in Jenkis and the build process for new branches or those where something has changed.
I have found the problem/solution. As I said, my Jenkins runs in a Docker container and is hosted locally on my PC (localhost:8080).
Through the credentials, the path from Jenkins into Bitbucket worked and so did creating the webhook. However, for this webhook, the Bitbucket server plugin entered its address (localhost:8080). So now when a push into a Bitbucket repo happens, this webhook was triggered on Bitbucket's localhost:8080 (so presumably Bitbucket itself and not Jenkins).
The solution was now quite simple. I used a tool called ngrok to make my localhost:8080 (on which Jenkins runs) accessible via a URL from the internet.
I then only had to store this URL in Jenkis in system configurations and adapt the webhook in my Bitbucket repository.

Why jenkins start all pipeline even if there's no changes for that particular folders?

I have microservice based application in Bitbucket. For all service need to deploy I'm using Jenkins pipelines. And each jenkinsfile is in root directory. Whenever a commit is pushed, all the pipeline starts even if there's no changes related to that particular build.
How to set the jenkins in such a way that it only trigger the pipeline of particular service where changes is made and pushed?

Auto create Jenkins job from source code repo - no jenkins interaction

I am looking to auto create jobs in jenkins upon pull request , branches, master push etc similar to what we do in Gitlab. My SCM is butbucket here.
I have so far setup docker based agent integration with Jenkins and butbucket, when I create a job and configure it to use repo it all works fine , but I just want to remove altogether a step of job creation in jenkins and want the workflow like this:
In butbucket source code repo to keep all pipeline configuration for and branch and tag to trigger Jenkins pipeline without touching Jenkins for job creation or any config creation. Just want to drive all via the script in code repo for pipeline .
Any recommendations or help for workflow would be appreciated
I got the answer to my Question , hence listing the steps for very simple use case for how it would work.
Steps:
Go to bitbucket server repository to which you want to enable pull request based trigger. Add Post Recieve Hook to this repository "Webhook to Jenkins for Bitbucket Server" , Enable this hook to have connection to jenkins. Enabling this plugin will issue POST request to jenkins each time a new Pull request is opened.
On Jenkins Server this will work with Blue Ocean Pipeline which by default will pick the change for pull request branch and trigger the job on each pull request.
Blue Ocean pipeline will by default create multi branch pipeline job to work with bitbucket repository.

How to use Jenkins pipeline to update a website on another server?

I've setup and connected a Jenkins (2.249) server to my GitHub account, so it has access to my repos and I've setup the GitHub webhook.
But I am having problems trying to understand how to create a multibranch pipeline job to detect when a push to my master branch happens and then I want to run SSH commands on another host to update a web server with the new code changes.
With Jenkins pipelines, I can't see how to detect when a push to master happens and then trigger the build? Is this possible with Jenkins? I have Blue Ocean installed as well.
Multi-branch Pipeline jobs periodically check the server for updates. It sets an environment variable BRANCH_NAME with the current branch during execution.
If you only care about the master branch, you should use a regular Pipeline job that only watches master.
See the docs

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.

Resources