Using the features provided by a plugin in a Jenkins workflow/pipeline - jenkins

I have a jenkins standalone job, that uses the MSTest plugin, it publishes the test result (.trx) on the jenkins UI. I want to use this feature of the plugin via the workflow script. How can i achieve this?
At the moment, i am using this batch file, but it need the extra utilities like the "msxls.exe" which doesn't comes with cloudbees jenkins out of the box.
stage name: 'Publish test result', concurrency: 1
bat 'C:\\bin\\msxsl.exe TestResult.trx "C:\\Jenkins\\plugins\\mstest\\WEB-INF\\mstest-to-junit_withOutput.xsl" -o JUnitLikeResultsOutputFile1.xml'
step([$class: 'JUnitResultArchiver', allowEmptyResults: true, testResults: 'JUnitLikeResultsOutputFile1.xml'])

If a plugin is compatible with the Pipeline plugin, then you can find out the appropriate Groovy DSL for it by enabling the "Snippet generator", choosing "step" and finding the desired build step in the "Build step" list.
It would look somewhat similar to the JUnitResultArchiver step you're already using.
However, unfortunately, the MSTest Plugin is not currently compatible with the Pipeline plugin, so it's not available in this list.
You would have to file a feature request to get this implemented.
The Pipeline plugin documentation also has some documentation for developers on how to make plugins compatible.

Related

NUnit-report does not mark build as error

Within my freestyle Jenkins-job I´m executing unit-tests via the "execute Windows batch-command"-step:
call "C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" MyAssembly.dll
call SomeOtherProcess
As there are tests that fail, I´d expected the build to fail as well. However the test-publishing-step for NUnit markes the build as unstable:
Build step 'Publish NUnit test result report' changed build result to UNSTABLE
If I´d remove the SomeOtherProcess-line from my batch-script, everything works fine and the errors produced by nunit are reported as error in the build-process.
I read a similar issue for the JUnit-test-reporter (Jenkins JUnit Plugin reports a build as unstable even if test fails). Obviously that reporter does not even support failing the build. I´m not sure if the same applies to the NUnit-reporter as well.
The plugin set the result to UNSTABLE because the option, by default, failedTestsFailBuild is set to false.
You can control the behavior applies of NUnit, setting failedTestsFailBuild to true. When you call from a scripted or declarative pipeline.
The issue is the GUI doesn't reflect all the options available for this plugin. There is a PR opened to include this option inside the freestyle pipeline, you can vote up or ask the status of this PR.
To change to an error you need to catch the unstable result and set it to failure using a plugin or a scripted or declarative pipeline.

How to compile Jenkins Pipeline Groovy locally?

Does anyone have the magic maven/gradle invocation to compile a set of jenkins pipeline DSL groovy files?
Groovy is not compiled (like C#), it is interpreted.
Depending on exactly what you are trying to test potential options are:
Jenkins Groovy Script Console under Manage Jenkins. Note: You will need to be an Admin to be able to access this.
Pipeline Syntax Generator. It is improving. Go to a build of Pipeline job and in the LHS menu you will see a 'Pipeline Syntax' link. Some items require you to first select Pipeline: Steps from the first dropdown.

How to use SauceOnDemand Plugin with Jenkins Pipeline

I have a freestyle Jenkins job with the Sauce OnDemand plugin installed. That plugin provides UI so I can define which browser and devices I wish to test on in the Job config. It works as expected.
Now I want to migrate my job to a Declarative Pipeline job.
The Pipeline Snippet generator, under the "sauce: Sauce" sample step, says I should do:
sauce('<guid for my saucelabs user>') {
// some block
}
Does anyone what //some block should be that would allow me to specify the browsers I wish to test on?
I am not using node, I am using .NET.
What am I missing?

How to extract Jenkinsfile by a custom script?

I've created a Jenkins job of type "Pipeline", and used an inline pipeline script. Now I'd like to put the script under version control and use the "Pipeline script from SCM" option (I think, I don't have to describe the merits of this).
However, our version control system (CA SCM) is not well supported in Jenkins: I couldn't make the plugin to check out anything.
We do have, however, some scripts for working with CA SCM that allow to check out things reliably.
So, my question is: Is it possible (and how) to have the Jenkinsfile under version control, do the check out for it by a custom script (e.g. using a .bat command) and then have the pipeline executed as if the Jenkinsfile had been extracted by the "Pipeline script from SCM" option?
I.e., as I understand it, I need a command in the pipeline plugin to execute a given Jenkinsfile.
You could try to use the feature "Prepare an environment for the build" from the "Environment Injector Plugin" (https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin) and provide a script file (or inlined content) to execute.

How can I publish NUnit test results using Jenkins Pipeline?

Trying to use the nifty Jenkins Pipeline, I had problems finding out how to publish NUnit test results.
I am able to run the tests by specifying the following command in the pipeline script:
stage 'Test'
bat '"C:\\Program Files (x86)\\NUnit 2.6.4\\bin\\nunit-console-x86.exe" "ProjectName\\bin\\Release\\UnitTests.net.dll"'
But how to make Jenkins "publish" the test results is not obvious. The Snippet Generator only suggests junit, and that does not seem to work.
I used nunit plugin version 0.21 and was able to publish results using
stage("PublishTestReport"){
nunit testResultsPattern: 'TestResult.xml'
}
(TestResult.xml is at the root of jenkins workspace in this above example)
Investigating the NUnit plugin for Jenkins led me on to this issue, where I found the solution:
step([$class: 'NUnitPublisher', testResultsPattern: 'TestResult.xml', debug: false,
keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])
Adding this to the pipeline script worked for me!
However, it seemed the following should also work (but at the present, apparently, it does not): Using the Snippet Generator, select this:
step: General Build Step
Publish NUnit test result report
This generates the following in the Pipeline script:
step <object of type hudson.plugins.nunit.NUnitPublisher>
This fails!

Resources