XRAY integration with jenkins - jenkins

Need step to integrate XRAY with jenkins , as per the official documentation we need to give JIRA url ,select cloud or server/data center and select the credentials of JIRA account , then the configuration id will be get generated ... So we need to use that config id in pipeline
Is there any other way just to add username/password of jira in jenkins credentials and connect with XRAY from jenkins

If you are using the Xray Jenkins plugin you must provide the mandatory information to communicate with Xray as described here: https://docs.getxray.app/display/XRAYCLOUD/Integration+with+Jenkins.
You also have the possibility to use the Xray API and control the parameters you need to ask for, if you pre-configure some parameters on the code and only ask for login and password. To connect to Xray you will need some mandatory parameters that are described here: https://docs.getxray.app/display/XRAYCLOUD/Version+1, how many of those you can have pre-defined is up to your usage.

First, please check if you are using Xray on Jira cloud or Jira server/datacenter.
To submit results from Jenkins you have 3 options:
use the Xray Jenkins plugin UI itself, and configure a project to submit the test results; this is pretty straighforward
use the Xray Jenkins plugin but from the pipeline; for that you need to generate the pipeline script
use either the Jenkins UI or the pipeline to invoke the API by hand; for this you don't need the Xray Jenkins plugin, you just need some tool such as "curl" to perform the HTTP requests (see example for GitLab and Xray cloud here, and for Xray server/DC here)
Note that for Xray in Jira cloud, you need to use client_id and client_secret to perform an initial authentication request (in case you're doing the requests by hand). These are obtained from an API key defined on Xray global settings.
For Xray on Jira server/datacenter, you may use Jira credentials (e.g. Jira username + password). It only requires you to perform one request and submit the test results.

Related

How to authenticate xray from jenkins pipeline script

For Xray on Jira server/datacenter ... Need authentication token to push the results from jenkins pipeline ... How to generate the token or if there is any other way to authenticate and push the test results
In Jira server/datacenter, usually the authentication is done using a Jira's user credentials (i.e., username and password). It's also possible to use Personal Access Tokens (in Jira datacenter only), but this is not that common; besides, these Personal Access tokens are totally unrelated with the authentication tokens used in Xray cloud in case you've seen that.
So, and first of all, you need to install the Xray Jenkins connector/plugin.
Then you need to configure a Xray instance, where you specify the server URL and the credentials (i.e., Jira username + password).
Then you can either use the UI to setup your build , on a freestyle project for example, and use the task "Xray: Results Import Task" as a build step.
If you're using declarative pipelines, on a pipeline type of project, then you can generate the pipeline syntax as follows:
Access Jenkins' Snippet Generator to faciliate the process of generating the pipeline script code.
You may access it, from the pipeline syntax link available from within your project.
Then select "step: General build step", "Xray: Results Import Task" and fill out the values you want.. it will then allow you to generate the script that you can include in your pipeline.
If you don't want to use the Xray Jenkins connector/plugin, you could also invoke the Xray REST API directly and perform a HTTP POST request to submit the test report, using the Jira user credentials and basic authentication. This could be achieved by invoking, for example, "curl" utility as a build step.

Publish the Screenshot/PDF of SonarQube Analysis Result from Jenkins to Confluence

I have a Jenkins job that will invoke SonarQube analysis on code pulled from a Bitbucket repository whenever there is any changes on the Bitbucket repository. At the moment, I was able to use the Confluence Publisher plugin to publish the URL of the build job to Confluence as a comment.
I was wondering if there is any way I could use Jenkins to screenshot the SonarQube analysis report (like in SonarQube web UI) and publish it directly to Confluence? (So that the user does not need to use the URL to go to the specific Jenkins build job, and then get the SonarQube analysis report URL, and navigate to the page to view the report)
Thank you.
Instead of using a screenshot, you can send a curl request from Jenkins to SonarQube REST API (5.3 and above) to get the project status from the quality gate after the code has been uploaded and analysed. The endpoint you'd likely want to use is: /api/qualitygates/project_status?prjectKey=<projectKey>&branch=<branch>
According to the web API docs:
Get the quality gate status of a project or a Compute Engine task.
Either 'analysisId', 'projectId' or 'projectKey' must be provided
The different statuses returned are: OK, WARN, ERROR, NONE. The NONE status is returned when there is no quality gate associated with the analysis.
Returns an HTTP code 404 if the analysis associated with the task is not found or does not exist.
Requires one of the following permissions:
'Administer System'
'Administer' rights on the specified project
'Browse' on the specified project
Once you have these results available, you can create a Jenkins user in Confluence and have Jenkins send a POST request to create a page or a comment with the results obtained.

In Jenkins what's the differences between Remote access API and Pipeline REST API

In Jenkins, we want to get the Pipeline stages information through API, e.g. a stage is success or fail. From another answer it seems we can achieve it through Pipeline REST API Plugin.
My question is:
Can Jenkinsapi and Python-Jenkins achieve the same thing? It seems they're designed for bare metal Jenkins, instead of the Pipeline plugin, right ? If that's the case, do we have similar Python library for Pipeline plugin?
Thanks!
You have all the info to answer your own question in the documentation you linked. Just to put it together:
Jenkins has a REST API
The pipeline REST API plugin injects new endpoints in the Jenkins REST API to give you access to several pipeline info
Python-Jenkins and jenkinsapi you mentioned above are both wrappers around the Jenkins REST API to help you develop scripts/apps targeting the Jenkins API in Python. Since those modules/libs are based most probably based on the core API specification, they most probably don't provide specific methods to target the pipeline endpoints (but you can probably extend that quite easily).
If you want to stay in Jenkinsapi, get_data() defined in JenkinsBase class could be used for querying Pipeline REST API directly. Not very sure if it's recommended or not.
Following codes works for me.
from jenkinsapi.jenkins import Jenkins
import requests
requests.packages.urllib3.disable_warnings()
# GET /job/:job-name/:run-id/wfapi/describe
url = 'https://localhost/job/anyjob/10/wfapi/describe'
jenkins = Jenkins(
'https://localhost',
username='username',
password='api_token',
ssl_verify=False,
lazy=True)
print(jenkins.get_data(url))

Jenkins: Limit Credentials to 'Manage Jenkins > Configure System'

We would like to use the GitHub Pull Request Builder plugin in Jenkins, however in order to use this plugin you are required to enter credentials in the 'Manage Jenkins > Configure System' section that gives access to a given GitHub Enterprise server.
Our issue is that credentials giving access to all of github are too strong to be stored in the credentials manager. I know that you can limit the scope of credentials by using the Folders plugin, however this just limits access to those credentials to jobs in certain folders. Is there a way to restrict credentials so they can only be used in the 'Manage Jenkins > Configure System' section?
Our issue is that credentials giving access to all of github are too strong to be stored in the credentials manager.
This is why you can also use a Personal Access Token. Check the documentation for the plugin at: https://go.cloudbees.com/docs/plugins/pull-request-builder-for-github/. This is not the official plugin page but having read both, this one keeps to the best practices in terms of credentials. The important bits are:
Go to your GitHub settings page.
In the left sidebar, click Personal Access Token.
Click Generate new token.
Give your token a descriptive name
Select the scopes to grant to this token. Pull request tester plugin require permission to administer repository hooks and access repositories: repo, public_repo, admin:repo_hook, repo:status.
Then you can follow the rest of the guide to enter the token in the plugin configuration pages.
Hope this helps.

How to trigger a Jenkins job from a status change in Jira

I have been looking for a while now for a way to trigger a Jenkins job from the status or a ticket/story in Jira changing status. To give a more detailed example when my team moves a ticket to the 'ready for test' column we would like to be able to trigger a sanity test pack in Jenkins, the ideal situation would then be that we are able to post the results (generated as a html) as a comment on the ticket within Jira. Failing that we would like to be able to publish the results as simply pass/fail.
I have recently been looking at the Jenkins Jira plugin but this does not seem to have the functionality to work both ways, in other words it can post results after a job has run but you cannot trigger the job from a change of status in Jira. Is there any such plugin available or is it something that we will need to create ourselves?
Cheers in advance
So, basicly there are webhooks in jira (https://developer.atlassian.com/jiradev/jira-architecture/webhooks). With it you can configure it to trigger specific url on issue status change. The specific url should be jenkins API, for example for triggering a build you should call an external url like (if you are building with parameters): http://server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value
Some more info https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
I have written a Jenkins plugin that supports JIRA status change trigger: jira-trigger-plugin.
This plugin also injects an environment variable of JIRA_ISSUE_KEY, so you can utilise this information to publish your result back to JIRA e.g. using REST API.
Please follow as mentioned below:
GIT:
You can set the web hooks for git/ bitbucket /stash on commit which inturn should change the state of task in JIRA.
JIRA:
Once you in JIRA. define the workflow for your task.
In this particular workflow you can set a post-function where the web hook should be configured. In this configuration of webhook in events define JQL as below:
status CHANGED FROM "To Do" TO "ready to test".
In the same mention the job that needs to be fired in the URL section.
You can look through webhooks in Jira :
https://support.atlassian.com/jira-cloud-administration/docs/manage-webhooks/
You also need to add the Generic Webhook Trigger plugin to your Jenkins :
https://plugins.jenkins.io/generic-webhook-trigger/
You can find here an example on how to use the Generic Webhook Trigger plugin with Bitbucket Github and Gitlab. https://github.com/jenkinsci/generic-webhook-trigger-plugin/tree/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd
It involved multiple steps
If you are using Git/Stash/BitBucket (which i implemented),
You can simply
configure the commit hooks in your Stash/Bitbucket
Attach events to your JIRA workflow
Jenkins JOB - post build events - configure Notify
Stash plugin Set the Poll SCM
That's it

Resources