Is there a way to read a build artifact file using the Groovy postbuild plugin?
Some context:
I have written some testng tests that are run by maven in Jenkins. Jenkins runs the tests, gives me the test results, etc. However, I have been asked to also store the results in HP's Application Lifeycycle Management (ALM). A coworker provided me with a post-build groovy script that can interface with ALM and store the test results. I have to pass these parameters to that script:
jobname
pass/fail status
test start time
My idea was to store testng-results.xml as an artifact and parse out the results with xmlslurper, but I don't know how to read the artifact from the groovy plugin. From the groovy postbuild plugin page I have gathered that it might also be possible to read the test results directly from the manager.build variable, but I don't have a lot of experience with Jenkins or this plugin and so far I have been unsuccessful.
I'm also open to other approaches as well. The groovy script is running on the Jenkins server, not on the slave node.
In case this is useful for anyone in the future, the solution that I went with was to find the artifact that I was looking for in manager.build.getArtifacts() and join that path with manager.build.getArtifactsDir()
Related
I'm doing a POC for a Java project in an AzureDevops CI/CD pipeline. I created a Maven project that has Selenium tests (TestNG) that run against a demo website which is independent of my project. I want to run unit tests in the build pipeline and UI Selenium tests in the release pipeline.
The Visual Studio test task seems to be the building block that I need. I think you can differentiate between unit tests & UI tests using the 'Test files' field like **\unit*Test.dll, **\ui*Test. Unfortunately, this task is not available/compatible for Java projects.
I was able to run the Selenium tests with the Maven task and Surefire plugin during build but remember, I only want to run unit tests during build.
I actually was able to run the Selenium tests in the release pipeline via a workaround which was:
Copy the whole project to the artifacts directory of the release during build (copy files task).
Add a Maven task to the release pipeline
Trigger the Selenium tests in pom.xml
Normally, you would only copy artifacts to the artifact directory so I think doing that is a huge hack.
Another problem is that Maven will build the project during build and release which is wasteful. To dial back the waste, some savvy Maven configuration might help. I was thinking about skipping compilation and resolve dependencies during release, but I don't know where to find the Maven dependencies in the DevOps ecosystem.
Am I missing something or is AzureDevops maybe not supporting Java all that well?
I do follow a method for Maven selenium tests on Azure DevOps. What I do is, in the build pipeline I build my tests in such a way that it produces a jar with all the dependencies and test classes in it. I also use testng in my approach. Next I copy my build Artifact to Artifactory. This completes the build. Now during the release I download my Artifact from Artifactory and I check the environment where i want to run and I inject the right testng file by running java -jar myfile.jar testngIT.xml. This runs my tests faster and better.
You can try just adding a test task in your release pipeline just as in the build pipeline.
And add a copy task in the build pipeline to copy the test codes and files to the build artifacts and publish it to release pipeline.
Below steps is just for reference(in classic view). Hope it can be of some help.
1, Add copy file task in the build pipeline to copy the all test files and all the dependent setting files to the test folder in artifacts.
2, Publish artifacts to release pipeline
3, In the release pipeline, add the task to execute the tests just like the way you do in build pipeline
I'm working on automating SVN Tag generation through JAVA and need some suggestions to start of with. This is how we do it manually - Check out a maven project/plugin from SVN repo and run a set of maven commands (mvn clean test, mvn release:prepare) to generate SVN tags, mvn release:prepare is the final command that would run unit tests, generate the tag and commit it to SVN and I'm working on automating this process.
I had a look at svnkit api which I can make use of to check out a project to the local file system and find a way to run the set of maven commands to generate tag URL, is there a maven JAVA plugin through which I can trigger maven commands? Or is there a much better way to do this other than JAVA?
I did my research on svn kit but could not find any relevant info to automate the maven process, probably I'm missing out on something.
It seems that you are looking for continuous integration.
I would recommend you to evaluate the use of Jenkins, which can be configured to periodically poll changes from SVN and launch a Maven build. Then, if the build succeeded and you decide to release it, you can perform a Maven release from Jenkins, which would take care of invoking the corresponding Maven goals. You can also configure a post-commit hook in SVN in order to launch a build after each commit.
I have an automation job (Java, Selenium and Cucumber) on jenkins. I'd like to know if it's possible to store my feature files somewhere on jenkins and configure my java project to read these features there. So doing this everyone who needs to edit the feature file can simple access the jenkins file and edit then, otherwise it would be necessary access the java project, edit the feature and commit and push it to the git repository (too complicated)
Should work if you change the features option for #CucumberOptions in your cucumber runner class. Just make it point to a different folder containing the feature files.
Yes, its possible. Jenkins downloads the code from repo to a slave jenkins node on which the test is executed. The feature files should be located on this node. The build tool or the configs (Maven/etc) should include the feature file locations in the test phase or the test plugins used. The #CucumberOptions also would then specify these feature files to run for the runner.
Note that #CucumberOptions is checked into the repo so you want to make that as generic as possible and then control the feature files in the jenkins node.
I am using the sonar ant task jar for sonar analysis so I setup it in the project-properties.xml and create an Ant build step in jenkins. When I build the job, the analysis works fine and I am able to see the results in the sonarqube server, but in jenkins no link to SonarQube is visible.
Do I really need to install the SonarQube plugin for the link to be visible for the job?
See also how to publish sonar result in jenkins server, or do we have sonar-report jenkins plugin
Normally you let SonarQube handle the code analysis on it's own and not by the Ant task (in the Jenkins job).
The Jenkins plug-in is there to trigger Sonar, to get latest sources (from the SCM) and run the analysis.
The results, are then made available on Sonar, but the Jenkins project, will provide a link to the results.
Workaround
There is (for as far as I know) no way to add a link, to an external generated report. What could be done, is add a simple HTML page, with a link to the Sonar server, to the project. And publish that simple HTML page, with the HTML Publisher Plugin.
I had been introduced to concept of CI lately and was trying to work on jenkins CI. I was stuck up in one thing . How to trigger executable testng files in jenkins CI. For ex locally in our machines we just run testng.xml to execute couple of test cases. In the same way how can we trigger this xml file to run in jenkins CI ?
In most cases with jenkins you wouldn't use an executable. Normally you'd run the wrapper for the tests (Junit/Nunit etc.) which Jenkins is fully capable of running on it's own.
You can use this article to run TestNG tests using Maven:
Running TestNG tests using maven
After configuration is completed just add Invoke top-level Maven targets step to the Build Steps in Jenkins (Maven plugin should be installed). The target should be test in this case.
If you will face with any errors during configuration, try to google them.
If you are not using any build tool like maven or ant, you can invoke it from command line as we'll and specify your suite file. Make sure to set the correct class paths http://testng.org/doc/documentation-main.html#running-testng
You can put this as a build step in Jenkins.
Add a compilation step prior to this step. I haven't ever tried it - have always used ant or maven, but that is where I would start exploring.