How to trigger a Jenkins build from XRay jira? - jenkins

I am trying to trigger a build in Jenkins directly from Xray. I have been successfully able to create a trigger in jira and has provided the webhook url and other information needed to run the build. But on triggering the build from any Test Plan, I am getting the following error:
Error publishing web request. Response HTTP status:503
ERROR: The requested URL could not be retrieved.
When i'm hitting the same webhook url in any browser, then the build is getting triggered in jenkins, hence it seems there's no issue with the provided webhook url.
One thing to note is that our Xray is in Jira cloud whereas the Jenkins is running behind a VPN. Can anyone help me in resolving the above issue?

If your Xray on Jira Cloud is trying to acess Jenkins, the Jenkins server needs to have a public URL. If you have it behind the firewall then it's not possible for Xray or any other tool to trigger it directly.
You can call the Jenkins URL from your browser because you are probably with your vpn connected.
The possible workaround would be to use a tool such as ngrok, as mentioned in the docs, to make a tunnel, but beware with the security implications of exposing your Jenkins url to the world.
For reference, Xray cloud provides documentation/examples showcasing how to take advantage of Jira Cloud automation capabilities to trigger jobs, for example in Jenkins.

Related

BitBucket Webhook - Unable to connect to Jenkins URL

I am trying to create a webhook in BitBucket to trigger a build in Jenkins, but when I enter my Jenkins URL, and I test the connection, I get the error "Unable to connect to the URL specified, check the host and port are correct." I am using the URL http://localhost:8080/bitbucket-hook/ (with the last back slash included) and I can confirm that in Jenkins, my "Jenkins URL" is set to http://localhost:8080/. In Jenkins, I have installed the plugin "BitBucket Server Integration", and under Configure System -> Bitbucket Server Integration, I have connected to the Bitbucket server (and when I test the connection, it says "Jenkins can connect with the Bitbucket Server", so I am pretty sure Jenkins is configured correctly). I don't have credentials set up in Jenkins for the Bitbucket Server configuration, is this necessary even though when I test the connection, it seems to be able to connect? Is my url for the BitBucket webhook correct?? Is there anything else you can think of that I might not have configured correctly so when I test the connection on BitBucket, it will connect properly?
I just ran through a similar setup, to answer to your questions:
yes, I think you will have to use credentials of a user having admin permissions on the repository upon which you want to create the webhook.
Read below, anyway the Webhook URL I got is in the form < jenkins-url >/bitbucket-server-webhook/trigger
The pipeline
According to my experience, the creation of the Webhook is demanded to Jenkins, you don't have to do anything on your own other than creating a new Pipeline object.
Having set the Bitbucket Server Integration configuration up in fact is not enough for the creation of the Webhook, to do that you have to
create a new Pipeline
flag the Build Trigger "Bitbucket Server trigger build after push"
in the Pipeline section, use as Definition "Pipeline Script from SCM" and fill the other fields according to the configuration you have set before.
Point 3 is saying you are retrieving your Pipeline definition from a file stored in Bitbucket itself, you can also customise the name of the file Jenkins is going to look for (by default this should be Jenkinsfile), and use the "Pipeline Syntax" option to get the snippet of code you will use as step in your Jenkinsfile.
Once you have created your Pipeline in Jenkins, the webhook should appear in the right section in your Bitbucket Server repository.

How to get jenkins pipeline test results into ReportPortal.io instance?

I have an automated Jenkins workflow that runs and tests a java project. I need to get all the data and results that are outputted by Jenkins into Report Portal (RP).
Initially, I was under the impression that you have to install the ReportPortal.io Jenkins plugin to be able to configure Jenkins to communicate with RP.
However, it appears that the plugin will eventually be deprecated.
According to one of the RP devs, there are APIs that can be used, but investigating them on our RP server does not give very clear instructions on what every API does or if it is what is required to get test data from Jenkins to RP.
How then do I get Jenkins to send all generated data to RP?
I am very familiar with Jenkins, but I am extremely new to Report Portal.
ReportPortal is intended for test execution results collection, not for jenkins logs gathering.
In two words, you need to find reporting agent at their github organization which depends on your testing framework (e.g. junit, testng, jbehave) and integrate it into your project.
Here is example for TestNG framework:
https://github.com/reportportal/example-java-TestNG/

Access GitLab Plug-in's API Token from Jenkins Job

I have instances of Jenkins and GitLab which are successfully connected. Part of setting up the GitLab plug-in involves providing an API token. I believe this is used by the plug-in to get details of the commit which is triggering a job.
I need to run a daily Jenkins job which collects some statistics using the API and then (using R) generates a report. So this is not triggered by an event in GitLab.
To complicate issues a little further, the R code will run inside a container (to avoid hving to install R and all the packages on every Jenkins slave),
It does not appear that the plug-in makes the token available to be used in jobs ... and I can see a sane reason for that.
Is it possible to access the API token from the plug-in?
There is a plugin which supports credential injecting (https://wiki.jenkins.io/display/JENKINS/Credentials+Binding+Plugin) to the builds which could be used later as an environment variable. Gitlab api token could be also selected.

BitBucket WebHook Jenkins

I'd like to configure bitbutcket to trigger a jenkins build.
I've spent some time researching this and all the answers are from a few years ago, and have not found any guides because things seem to have changed since.
What I'm trying to do:
A bitbucket push to a particular branch triggers a build.
What I've got:
Bitbucket web hooks which fires HTTP request to Jenkins on a push to any branch. I've also installed the Bitbucket plugin on Jenkins which adds a check box in the job config Build when a change is pushed to BitBucket. This checkbox doesnt seem to work (maybe I set it up wrong? minimal docs for this), despite me pushing to the configured branch in the SCM section.
Problem 1: Bitbucket does not fire a GET, but another request which causes a 403. I tested with postman, and it works with a GET, but not a POST.
Problem 2: This HTTP build request is fired on pushes to any branch. While the build is still restricted to a particular branch, it seems unnecessary to be rebuilding all the time.
How do i address these issues? Bitbucket does not seem to be very flexible in customizing this. The Jenkins plugin for bitbucket has a lot of 'bad' reviews. How are developers currently doing this?
SPECIFIC solution for Jenkins CI server--Webhook to Jenkins for Bitbucket plugin has been commercialized in latest version of Bit-Bucket and the current price is around $4800 which was earlier a free offering, because of this, guys who want to save their bucks, can go to the alternative solution by using webhooks feature of bit-bucket:-
Steps to create a webhook:-
BitBucket Side
1) Go to your bitbucket repo, click on Repository Setting, under WORKFLOW got for WEBHOOKS option and create a webhook.
a) creation of webhook:- URL https://JenkinsserverURL/git/notifyCommit?url=https://bitbucket.repository-link/repository.git
b) In the name tab, give any name of your choice
c) click on TEST CONNECTION before saving it. Make sure you get http status 200
d) View details your logs, check your request and response is correct.
Things to take care of from
Jenkins Side:-
1) Make sure repository mentioned in bitbucket webhook is used in Jenkins job.
2) In SCM option, activate/select Poll SCM option, don't mention anything in the schedule, leave it blank.
3) configure rest job,
Whenever your git repo observes any change an automatic build will get triggered in Jenkins. By default push trigger is activated and if you want to activate other action, please select those events while creating webhook.
***to specify the branch in repository webhook:-
http://yourserver/git/notifyCommit?url=<URL of the Git repository>[&branches=branch1[,branch2]*][&sha1=<commit ID>]
Cheers,
Is your Jenkins URL accessible from your bitbucket server? If yes that it should be fairly simple to do it. You add the webhook in your repository as http://<url-of-jenkins>/git/notifyCommit?url=<url-of-repository>. When jenkins receives this POST, it automatically triggers builds on those jobs that use this git repo with that URL you give in webhook.
But you also need to make sure your Build Schedule is set to empty for those jobs. otherwise it wont get triggered. You can specify a branch in webhook URL too
See the Push Notification from repository here
https://wiki.jenkins.io/display/JENKINS/Git+Plugin
For anyone here after July 2022, here are the simple steps I followed to make it work.
Create a live Jenkins URL
First, create a tunnel from a live URL to your local Jenkins URL using ngrok because using locahost:8080 directly as your webhook URL on bitbucket will simply not work as bitbucket does not recognize your local computer.
ps: ngrok claims to be the fastest way to put anything on the internet and I agree,
you can use it beyond Jenkins once you know the trick,
such as quickly handling out your localhost react app for testing by your friends
out of your local network
To do this is simple. For Linux:
Install ngrok snap install ngrok
Add authtoken ngrok config add-authtoken <token>
Don't have an auth token, sign up
Start a tunnel on your Jenkins port eg ngrok http 8080
To know more and for other OS, check ngrok download page
You will then get a response like
ngrok (Ctrl+C to quit)
Hello World! https://ngrok.com/next-generation
Session Status online
Account <your email>#<domain>.com (Plan: <plan type>)
Version 3.0.6
Region Europe (eu)
Latency 162ms
Web Interface <web interface url>
Forwarding https://<your-assigned-host>.ngrok.io -> http://localhost:8080
Basically, the web interface URL on click gives you a web interface to inspect all the requests being tunnelled from your ngrok live URL to your local host.
Forwarding URL is basically a proxy to your localhost, so when you want to configure webhook, instead of using locahost:8080, you replace it with ngrok URL eg https://syue-162-34-12-01.eu.ngrok.io and all requests get tunnelled to localhost:8080
Hook up the URL on bitbucket cloud
Secondly, configure your Bitbucket repository with a Webhook, using URL JENKINS_URL/bitbucket-hook/ (no need for credentials but do remember the trailing slash) eg https://syue-162-34-12-01.eu.ngrok.io/bitbucket-hook/
If you are using bitbucket server and not cloud or you want to know more, the bitbucket plugin documentation for Jenkins is pretty straightforward and easily understandable, see bitbucket plugin
then you can inspect all your webhook requests on the web interface URL or via your terminal as well as check your build logs on Jenkins via your localhost port or ngrok live url.
Disclaimer: I have not figured out how to enable build only when a specific branch change but you can configure jenkins to only build a specific branch or any branch created as your need may demand, check Source Code Management and Build Triggers

GitLab and Jenkins integration

I've read the differences between Gitlab Community and Enterprise in this page: https://about.gitlab.com/features/
Based on that page I understand the integration with Jenkins is only available in the enterprise version. However, I've seen that using web hooks I can trigger builds in Jenkins when a push happens in Gitlab.
So my question is which is the difference between community and enterprise regarding the integration with jenkins?
On the merge request page, there is a state widget that shows the status of tests for that particular merge request, and on your project home page, there is test status badging. These two UI elements only show up if you enable a 'ci service' on the project. In community you can turn it on with Gitlab CI. In enterprise you can set it up to work with jenkins.
Based on that page I understand the integration with Jenkins is only
available in the enterprise version.
This is no longer true, the Jenkins GitLab Plugin (from a 3rd party) works to hook Jenkins into GitLab as a CI provider.
The wiki page has an example setup with lots of details you'll need to get it working.
This will give per-commit build/test status indicators in GitLab and also hook into the Merge Request system (both in the local repo and when merge requests come from forked repos).
You can also integrate GitLab with Jenkins using the Generic Webhook Trigger Plugin.
An example of integrating with that plugin, to perform static code analysis on merge requests, is available in the Violation Comments to GitLab Plugin wiki page.

Resources