I would like to ask is there any way to query run time build steps by using Jenkins pipeline REST API? I refer to this link https://github.com/jenkinsci/pipeline-stage-view-plugin/tree/master/rest-api and it seems like I can't get a run time build steps command line that I configure for Jenkins pipeline job.
Any suggestions?
It seems there is no possibility to get this information via the REST API. I found a solution somewhere.
With
http://Serverurl/job/jobname/config.xml
you can download the config file and parse the XML. Doing it with PowerShell and it's working fine.
Related
I am new to Jenkins, just finish to configure my first build. My question how can I run Jenkins build from my pc? I mean via command line or some script or java code, I just need to trigger it. Where do I start?
Try reading the documentation about consuming jenkins API, see the examples using curl CLI tool.
Also here's a Java API Client example for you to inspect.
Problem: I am setting up jenkins + sonar + github integration for automatic pullrequest static code check through sonar.
My Configuration:
Installed Sonar with github
Installed jenkins
In jenkins post-build action I have the following properties
-Dsonar.github.login=bhuwang
-Dsonar.github.repository=company/repo
-Dsonar.verbose=true
-Dsonar.analysis.mode=preview
-Dsonar.issuesReport.console.enable=true
-Dsonar.forceUpdate=true
-Dsonar.github.login=gitusername
-Dsonar.github.oauth=token
Token was generated from my github account.
In this link I have read that I have to provide the following properties while running sonarqube:
I have added all except sonar.github.pullRequest properties. I don't know how do I get this property value dynamically. Seems like above four properties are must to work properly.
Edit: I have found the way to add property -Dsonar.github.pullRequest=pullrequestNo
And the good news is it is working perfectly fine now with hardcoded pull request no. but I need the dynamic way to get the pull request no.
Does anyone know how to get the pull request no. dynamically inside jenkins.?
I have found that pull request builder will work but no luck at my end. I am not able to use pull request builder environment variables inside sonar properties.
https://issues.jenkins-ci.org/browse/JENKINS-24590
Finally I am able to solve this issue. Here is the detail:
Install Sonar with GitHub plugin.
Install Jenkins with the following plugins
GitHub Pull Request Builder
SonarQube Plugin
GIT plugin
GitHub plugin
Follow this link to setup pull request builder plugin: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-EnvironmentVariables
Global Jenkins System Setup:
Goto Manage Jenkins -> Configure System
Configure jdk
Install sonarQube Runner
Configure Sonar
Git WebHook Setup
PullRequest Builder Setup
Create Free Style Jenkins job
add github url to GitHub Project section
Setup Source Code Management Section
Setup Build Trigger
Setup Sonar for post build actions
In the additional properties section provide the following sonar properties
-Dsonar.sourceEncoding=UTF-8
-Dsonar.analysis.mode=preview
-Dsonar.github.repository=company/repo
-Dsonar.github.login=gitusername
-Dsonar.github.oauth=oauthtoken
-Dsonar.host.url=sonarhostedurl
-Dsonar.login=admin
-Dsonar.password=pass
-Dsonar.github.pullRequest=${ghprbPullId}
${ghprbPullId}: this will be provided via github pullrequest builder plugin
Note: The job should be triggered through pullrequest builder plugin otherwise ${ghprbPullId} will return blank. If you run the job manually this will not work for that you have to pass this ${ghprbPullId} property as a build parameter. If you want to check the environment parameter available follow this Git environment variables for use in executing Jenkins shell scripts
I hope this helps.
Too long for a comment so I'll have to write it here.
After some research on the web I've found a question on SO from someone a few steps ahead of you in the process of trying to setup a similar system, here. They're trying to get this all working with Maven, I'm not sure if you are also, but either way you can then see the link they've been using to help them with their script:
https://github.com/SonarSource/sonarqube/blob/master/travis.sh
This shows they need to write a script that will retrieve the pull number dynamically for them. I think you may need to follow a similar approach and write a script that will retrieve the number for you, I believe one of the github conf files keeps track of the current pull request number for its own tracking purposes.
Not really as straight forward an answer as you might have been hoping for, but hopefully this is new information that helps you get there.
See my project's implementation Jenkins + SONAR + Github with code at
https://github.com/lqtruong/ci
I have been using Cloudbees Jenkins as a service and I'm trying to setup my local Jenkins which I got different results from Cloudbees Jenkins.
If I use this curl command to get the latest successful artifact.
curl http://endpoint.cloudbees.com/job/jobname/20/artifact/project_name/build/distributions/*zip*/distributions.zip
I got a zip file with this structure.
distributions/my_artifact.zip
But if I do the same command on my local Jenkins
curl http://localhost:8080/job/jobname/20/artifact/project_name/build/distributions/*zip*/distributions.zip
I just got
my_artifact.zip
which one is correct? And why they are different? I actually want my local Jenkins to produce the same results as as cloudbees.
I'm using Jenkins 1.534.
The behavior on the CloudBees hosted Jenkins is the traditional and intended behavior. It looks like you found a bug in development builds of Jenkins, which I filed as JENKINS-19947.
http://jenkins-ci.org/changelog
Read it.
* As of 1.532 download of artifact ZIPs was broken. (issue 19752)
There is a sonar plugin for jenkins, it triggers the sonar build inside CI (jenkins), it is useful.
While now I want to see the sonar result inside jenkins without jumping to sonar websites, it is useful if I just want to see some key data for this job.
It could be sonar-report plugin in jenkins.
Do you have similar needs ?
One ugly solution I used so far is to use Sonar Web API.
I add one curl command in the end of job (build steps) to fetch the needed metrics like
curl http://sonar.sh.cn.ao.ericsson.se//api/resources?metrics=qi-quality-index,coverage,test_success_density&resource=54936 --output sonar-result.xml
Then I archive the sonar-result.xml to make it visible inside the job.
You can try using Mashup Portlets plugin for Jenkins to configure the results in Jenkins Dashboard.
PFB URL for the plugin.
URL:- https://wiki.jenkins-ci.org/display/JENKINS/Mashup+Portlets
Could someone please elaborate on how to use jenkins apiToken for build through rest api.
I want to use user based authentication for Jenkins build.
So I have that apiToken with me but when I am trying to build a job I am getting forbidden exception.
I have followed the below url for build a job.
https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients
There is a project called Python Jenkins that provides the wrapper around the Jenkins REST API. I believe you may find a sample of using the authenticated build invocation there. You may find it here