Can't get build artifacts to display properly in Jenkins/Hudson - hudson

I currently Jenkins to as my continuous integration system and I use Gradle to build my project. Without changing anything Gradle by default puts all the build artifacts under the /build folder in the workspace. This obviously doesn't work well since the build artifacts get overwritten by the following build.
I have modified my script to output the files in the /builds/[BUILD_ID] folder on Jenkins, which puts the build artifacts in the correct build folder on the CI system, but they don't show up in the Jenkins gui when you navigate to a specific build.
How do I get my build artifacts to display in Jenkins? Where do they need to be put, in order to show up for each build?

In the Post Build Actions section of your Jenkins job configuration, select "Archive the artifacts" and specify which files to archive. Jenkins will save them with the rest of the build data and provide links to each file on the build page.

Related

How can jenkins find junit.xml in a zip file?

I am running Jenkins on a script, that generates a junit.xml report file and other files. However, all those files are zipped by the script, hence Jenkins cannot find it.
Is there a way to make Jenkins unzip the .zip file , find my particular junit file and generate the run results ?
All this is in Linux.
Thanks
Jenkins has the ability to execute arbitrary shell commands as a build step, just add the 'Execute Shell' step to your build and put in the commands you want (presumably 'unzip' would be among them).
Once you've extracted the xml, provided your internal tool generates it using this schema the JUnit plugin just needs the path you extracted to and it will show the results on the build page.
If you have the option, I would really suggest executing your tests via gradle or maven, as outputs from those tasks will produce a report that Jenkins (and other tools) can already read, and can streamline the job setup process for your users. But, if you can't get away with that, the above should work for you.

Custom Reporting to Jenkins

I'm trying to hook up our own private testing tool to Jenkins. I'm able to run the test through the command line and create a report on my local machine. I will need to convert that report to xml JUnit format, specifically for Jenkins. Once that is done, how do I associate the xml file that was just created to the most recent job. This way the correct report gets put with the correct job?
The way Jenkins works is simple: you create a job and Jenkins runs it. Every run of a job is called a build. If you configure the job to look for test report files at the end of a build, the test reports are loaded and presented in the Jenkins UI. There is no way to submit test reports to a build outside of the build or after the build.
Usually this is not a problem. You run your test program/script as part of the build and it produces xml files in the JUnit format. When all the build steps are done, Jenkins looks for the xml files and loads them. You have to tell Jenkins to do it, though. You open the job configuration and you add a new post-build action titled "Publish JUnit test result report". Then you give Jenkins a pattern it uses to search for the files. You can use **/*.xml which means Jenkins will look for all *.xml files in every directory and subdirectory. Or you can e.g. use **/testreports/*.xml if you know where the test reports are going to be.

Can Jenkins store artifacts outside the job directory?

I currently have Jenkins set up with a number of jobs, but it's proving difficult to back up because the artifacts are stored within the job directory. I'd like to back up the job configurations and artifacts separately. I'm sure I remember reading somewhere that Jenkins now has an option to store them outside the job, but I can't find this.
Is there any configuration option that does this while still making the artifacts visible from within the job on the Jenkins interface? (ie rather than merely an add-in that copies the artifacts elsewhere)
Go to your jenkins configuration page, e.g.
http://mybuildserver.acme.com/configure
At the top of the configuration page there is a "home directory" setting. Click the "advanced..." button below it.
Now set the "Workspace Root Directory" to e:\jenkins-workspaces\${ITEM_FULL_NAME}, and "Build Record Root Directory" to e:\jenkins-builds\${ITEM_FULL_NAME} or something similar.
Warning: I run Jenkins 2.7.2 and noticed that certain features don't work properly after configuring Jenkins like that. I saw problems with folders and problems with the multi-branch project plugin. Check the status of those issues if your rely on these features.
As you can see here, there are many plugins to deploy artifacts anywhere you want/need, on FTP, CIFS, Confluence, Artifactory.... especially the ArtifactsDeployer that will allow you to make a copy of the artifacts in the Jenkins Home.
Thank you Sam, for your post, which directed me into the right direction to solve my problem.
Have been searching for a way on how can I make a symlink to the Job-Archive of a build for multibranch projects. Up to now, we used to manually search for the correct folder basename in the filesystem and added that one to the Jenkinsfile.
Now, I can simply use
jobOutputFolder = currentBuild.rawBuild.artifactsDir.path
and use that in my script.
If security is a concern, I could implement that as a shared library additionally.
Try the Use Custom Workspace build option. From the Jenkins popup help:
For each job on Jenkins, Jenkins allocates a unique "workspace
directory." This is the directory where the code is checked out and
builds happen. Normally you should let Jenkins allocate and clean up
workspace directories, but in several situations this is problematic,
and in such case, this option lets you specify the workspace location
manually.
This option is also available under advanced project properties of multi-configuration project builds.
A groovy script under "Prepare an environment for the run" will always run on the master, and this groovy script can create a symlink to where you really want artifacts archiving to archive_to which SHOULD include the job name and build number:
if (! Files.createSymbolicLink(Paths.get(currentBuild.artifactsDir.path),
Paths.get(archive_to.getCanonicalPath()))) {
throw new RuntimeException("Can't create symlink to archive dir")
}
Of course (sadly) when old builds are purged by Jenkins the old artifacts are left because jenkins will not follow a symlink when purging, even if jenkins owns the symlink and the target (shame).
I workaround for that may be to point a symlink back from the new archive dir, then, when jenkins purges it's archive dir, the new symlink will dangle and a cron job can then later delete the new job archive dir
Copy Artifact Plugin (https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin) adds a build step for retrieving files from another project's workspace to current and work from there.

Jenkins build outside of workspace

I am new to Jenkins/Hudson and am trying to migrate a C make-based project from buildbot. For legacy reasons, the build system is hard-coded to build outside of the versioned source tree (git), one directory above, in a separate directory. E.g.:
workspace
.git
foo
bar
build
artifacts
Besides the fact that it ends up creating a directory outside the workspace, Jenkins won't recognize items in the build/ directory above to archive as artifacts.
How can I make this kind of build system work with Hudson? Building in-source-tree is not a short-term option. The only option I found was "use custom workspace," but all this does it hard-code the workspace directory to some other directory.
To answer my own question: there is indeed an option in Jenkins git plugin to check out to a local subdirectory instead of the root of the workspace. With the git plugin, click on the Advanced button and fill in the field "Local subdirectory for repo (optional)".
I don't find the option that djs mentioned, but you can specify a different work directory:
Configure job
Extended Project settings
Use custom work space
This can be set to everywhere you want, also the workspace of a different job.

Ant script generate a findbugs_result.xml, but the hudson can not display on main interface. why?

Findbugs script in build.xml:
Findbugs checks Coding...
Findbugs checks Coding...
genetate a findbugs_result.xml.
Download Findbugs plugin for hudson.
Enter findbugs_result.xml path for hudson.
But hudson can not display on main interface. why?
I've found some annoying inconsistencies in the way Hudson stores paths; sometimes you use the overall workspace directory for the Hudson job and other times you have to use the path to the code that the job checks out of source control. For example, if your code gets checked out to MyProject under your workspace directory, and then the test XML files go into MyProject/target/test-reports, try specifying the path with and without the MyProject at the beginning of the path.