Jenkins does not run the building process after a push - jenkins

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.

Related

Trigger Jenkins Multi-Branch Pipeline from GitLab push

I run a Gitlab and a Jenkins server locally. I connected those two using the gitlab-branch-source plugin. For every repository in gitlab i create a multibranch-pipeline job in jenkins. When a user pushes code, I want the corresponding job to be executed.
I'v tried a solution suggestend in this post and this one. Both of them don't seem to work.
In the gitlab server settings on the jenkins server I've set the check at "Manage Web Hooks". The personal access token which is used for the integration has the scopes "api, sudo".
What else could I try?

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

integrating gitlab with jenkins using webhooks does not work

I am trying to trigger jenkins pipeline on gitlab push to branch and tag.
Using Jenkins ver. 2.176.2 and gitlab version 10.7.3-ee.
Although I have supposedly set up the webhooks properly, I do not see the jenkins job being triggered.
I have installed the gitlab plugin for jenkins, and configured the gitlab server, including the Personal Access Token for GitLab APIs access generated in gitlab.
I have defined the webhook (currently requesting trigger on all events). (for testing, ssl verification is off).
When testing the webhook in gitlab, I consistently receive HTTP error 500.
In jenkins pipeline job, I have selected "build when change is pushed to gitlab. gitlab webhook..." - this is the URL I used when defining the webhook in gitlab, under "integrations" section.
When pushing to gitlab, I see no event listed under "integrations -> recent deliveries",
I see no log under jenkins logs "com.dabsquared.gitlabjenkins" logger (set to log level "FINEST".
And lastly, the pipeline job is not triggered as I expected.
Any leads will be very helpful.
Adding printscreen of the Jenkins configuration of the gitlab for reference to the comment I added on possibility this is issue with the personal access token
Jenkins gitlab server configuration
Go to Settings of Gitlab Project -> Integrations and type in the Jenkins Job project url in 'URL'. URL should take either form:
http://JENKINS_URL/project/PROJECT_NAME
http://JENKINS_URL/project/FOLDER/PROJECT_NAME
Notice that the url does not contain "job" within it and instead uses "project".
Make sure under Triggers, you have "Push Events" checked as well if you want the job to trigger whenever someone pushes a commit.
Finally, run a build against your Jenkinsfile first before testing the webhook so Jenkins will pick-up the trigger settings for Gitlab.
Please refer the link for more details.

Bitbucket webhook to trigger Jenkins job

I'm having trouble getting my webhook in bitbucket server to start a Jenkins job. I've read through the other answered questions on here and can't get it going.
Bitbucket setup:
No special plugins installed
In repository settings I have a webhook set up
URL: http://[my jenkins url]/bitbucket-hook/ (yes I have the trailing slash)
Repo Push event selected
Jenkins setup:
Bitbucket plugin installed
Created new job
Set SCM to Git and added repo details
Set branches to build to either ** or refs/heads/rob-jenkins (a branch in git)
Build when a change is pushed to bitbucket selected
What I do:
I make a change to a file in rob-jenkins branch, push and the job is not started in Jenkins.
What I see:
In bitbucket, repo settings, webhooks I can see the webhook fired as soon as the commit is pushed. It has a 200 http status code, response body is empty.
In Jenkins I've set up a logger for
com.cloudbees.jenkins.plugins.BitbucketHookReceiver
com.cloudbees.jenkins.plugins.BitbucketJobProbe
com.cloudbees.jenkins.plugins.BitbucketPayloadProcessor
com.cloudbees.jenkins.plugins.BitBucketTrigger
And when I look at those logs I can see only 1 entry from com.cloudbees.jenkins.plugins.BitbucketHookReceiver
Received commit hook notification : {"eventKey":"repo:refs_changed","date":"2018-05-22T12:18:11+1000","actor":{"name":"xxxxxx","emailAddress":"xxxxxx#xxxxxx.com","id":53,"displayName":"xxxxxx","active":true,"slug":"xxxxxxx","type":"NORMAL"},"repository":{"slug":"xxxxx","id":1,"name":"xxxxx","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"SS","id":2,"name":"xxxxx","description":"xxxxxx","public":false,"type":"NORMAL"},"public":false},"changes":[{"ref":{"id":"refs/heads/rob-jenkins","displayId":"rob-jenkins","type":"BRANCH"},"refId":"refs/heads/rob-jenkins","fromHash":"1d9ad42fa404c893853094b0072e5b839f787589","toHash":"9bf7dc873f355259e4338ee80afbd246ecbb48a9","type":"UPDATE"}]}
There are no other entries in the log.
In the job itself, the BitBucket Hook Log screen just says "Polling has not run yet."
No idea why it isn't triggering the Jenkins job... what am I missing?
I've tried setting the Poll SCM manually and that didn't make a difference.
I've done a manual build and it works fine
as commented by #tomas-bjerre the resolution was to use a different plugin
I would recommend using thie plugin instead: github.com/jenkinsci/generic-webhook-trigger-plugin – Tomas Bjerre yesterday
No plugin needed. Just add a post-recieve hook under your repo in Bitbucket. On Jenkins, under Build Triggers, Trigger builds remotely (e.g., from scripts) Trigger builds remotely (e.g., from scripts) and specify an Authentication Token. A bash or python script can be used for the hook. Anytime a git push is run (not just a commit), you trigger a build!

Resources