show fxcop result using jenkins pipeline as code - jenkins

I have pipeline job in jenkins which build the .net solution project. Run the MS Test and also does the static code analysis using FxCopCmd using command line (batch). I would like to show the fxcop result in jenkins itself. I know there is a Violation plug-in already available but it helps in FreeStyle job. How can we show the result using Pipeline Job?

Related

Are there any ways to improve the developer experience of writing a Jenkinsfile?

I've been following a few tutorials to get started with Jenkins, and they all describe the same workflow:
Write a Jenkinsfile
Add it to SCM
Add the project to Jenkins via the Web UI
Trigger a build in Jenkins
Modify the Jenkinsfile
Commit changes
goto 4
Is this really the only way to develop a Jenkinsfile? It's a terrible developer experience.
Does Jenkins include any developer conveniences, like the ability to watch a Jenkinsfile and trigger builds automatically, without using SCM?
Are there any other tools out there to improve the developer experience of writing Jenkinsfiles?
With jenkins you can automate the execution of a job or Pipeline with:
jenkins-cli.jar command line tool
REST API
You can also install plugins to configure hooks on your SCM server and automate the Pipeline or Jenkins job execution on every commit event.
If using github you can use the GitHub plugin
If you want to skip the adding project via the web UI, you can consider to automate the project creation by using:
multibranch pipelines that way every branch of a repo will be scanned in order to find a Jenkinsfile and if it is found it will be parsed and the project will be created
Use job dsl to automate the Pipeline project creation.

Is there any alternative for promoted builds in Jenkins

I am using Jenkins pipeline scripts for all my jobs. I was using Promoted-builds plugin for other jobs, But its not compatible with Pipeline scripts. Is there any alternative? .
Pipeline script has manual input but that does not solve the problem as the job is in build queue until the input is provided.
I have been using Hudson / Jenkins since 2007. I have never found the Promoted Builds plugin to be that useful.
Instead I use labels / tags from different jobs (Build and Unit Test, System Test, Performance Test) or artifact repositories as markers of where an version or artifact has progressed to in the overall "pipeline".
Regarding Artifactory:
In my Build and Unit Test job, on Success of the Integration branch I tag the source code and upload the tested artifact to Artifactory.
In my System Test job, on success I call my Performance Test job as a downstream job passing the version number of the successfully tested package as a parameter.
In my Performance Test job, on success I "copy-promote" the tested artifact to the next designated location in Artifactory.
HTH

Jenkins: how save the logging outputs saved through Gradle testing into Jenkins Build History

I am working with:
Jenkins 2.64
Gradle 3.5
Spring Framework 4.3.8
I am able to execute a Main java class through a Gradle task through Jenkins.
Therefore I can execute a Job N times to work around JMX and for each Job execution I have the Build History where I am able to see the logging outputs from my business classes for each interaction.
Note the history saves each logging outputs for each Job's execution
The problem is with testing.
Through Jenkins I am able to execute a Job related with a Gradle Test command, such as: gradle test --tests. Here two behaviors:
Gradle saves the logging outputs from my business classes through its own output directory build\reports\tests\test (it is the expected, I am fine with this)
Jenkins worked fine about the execute the Gradle test command but all the logging outputs are only posted through the Gradle Test reports but not in Jenkins, it in Build History.
Thus the Jenkins does not contain the logging outputs from my business classes. Therefore if I execute N times through my developing cycle the Test Job. I only am able to see the latest logging outputs only through the Gradle Test Reports, sadly Jenkins does not keep these logging outputs through Build History.
How resolve this? Some basic configuration or a plugin is need it?
In order to save junit reports in Jenkins, you can use JUnit Plugin
Individual reports are located at build/test-results/test/.xml*
If you are using Declarative Pipelines you can use the following script
junit 'build/test-results/test/*.xml'
Since you are pointing to build\reports\tests\test\index.html which is the gradle test report, you can also save that report using HTML Publisher Plugin
My suggestiong is to use JUnit Plugin for better integration.
To save artifacts from your build you can use the archiveArtifacts pipeline command
It would look something like:
archiveArtifacts artifacts: 'build/reports/tests/test/*'

What is the advantage of the Jenkins SonarQube plugin over adding sonar:sonar to maven build step

I am using Maven as a build tool and Jenkins as a CI tool. Currently I have a Jenkins job configured with a Maven build step.
I started using SonarQube and was wondering what is the advantage of using the Jenkins SonarQube plugin and configuring the SonarQube analysis as a post-build-action over simply adding sonar:sonar to the goals of my existing Maven build step.
Thanks and best regards,
Ronald
You can save a lot of configuration. So, if you use jenkins sonar plugin you can centralize database credentials and sonar credentials but if you make a decision about execute sonar:sonar in each jenkins job you will configure each with the same credentials.
I just found: Why use sonar plugin for Jenkins rather than simply use maven goal "sonar:sonar"?
And to add one reason: Using the Jenkins SonarQube plugins one can specify "Skip if triggered by SCM Changes". This is nice if you trigger your Jenkins job for each commit but only want to do a SonarQube analysis at a scheduled time, e.g. one per night.
And here is a summary of the the points made by "emelendez":
Centralize database credentials and sonar credentials Use jenkins
Use jenkins sonar plugin configuring SonarRunner for non Java projects
I've just changed to maven-sonar-plugin from the Jenkins SonarQube plugin to avoid divergence of information between the pom.xml and sonar-project.properties.
For example, developers elsewhere had bumped the project version number in the pom.xml, but they don't use the Jenkins builds and didn't care about the sonar-project.properties (or probably understand it). By switching to the maven plugin instead, the project version is defined once and referenced in the sonar property set within the pom.
The downside is that I no longer have the SonarQube link from the project's Jenkins page.
I'm not sure where the responsibility might be for adding this link back for projects using maven-sonar-plugin... The link is "owned" by the Jenkins SonarQube Plugin, but this is not being used here. Meanwhile the maven-sonar-plugin component is integrating with maven not Jenkins.
Something would need to observe the build and extract the SonarQube link which is emitted as a [INFO] ANALYSIS SUCCESSFUL, you can browse http://... line in the log.

how to publish sonar result in jenkins server, or do we have sonar-report jenkins plugin

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

Resources