file system as hyperlinks in Jenkins console - jenkins

I have to log a file system path in the Jenkins log after it completes the run. I know echo 'file://filesystem/folder' will be logged as a hyperlink in Jenkins pipeline, however clicking on it doesn't seem working. Is there a way to click on the link which will be redirected to file/folder system in your computer?

I'm providing this answer assuming that it's okay for you to copy the file in question from outside $JENKINS_HOME into the job's archive.
Within the job, in a build or post-build phase Execute Shell box:
cp $FILE_PATH $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/archive
Where you only need to replace $FILE_PATH and the rest of parameters are known to Jenkins. A hyperlink to the last built file will appear in the list of the job's artifacts, visible on the job's main page, as well as in each build, specific to it.

Related

How a Jenkins non-privileged user can download a file from workspace?

I have configured Jenkins job as a UI for my Python script, which takes an input file as a parameter, processes it as I need and writes results into output file which is placed besides the script in the job workspace. This job is intended to be executed by regular non-pivelege Jenkins user. And they permissions do not allow them to access anything in the workspace.
How can they retrieve the output file?
Should I configure ext email plugin, so the file will be sent to users as an attachment?
As a user izzekil mentioned, a good approach is to archive the file you need as a build artifact. After archiving the file will be available for download from Jenkins UI.

What information is exactly captured in console output and build artifacts in jenkins?

For example in the link below, on the left there is tab "Console Output" and in the center first hyperlink as "build artifacts". If we open these hyperlinks we see files. Could you please help me know what exactly is logged in the files?
https://builds.apache.org/job/Apache-Falcon-Pull-Request-Build/236/
In Jenkins, every job have build steps, each build step can be anything from running shell\batch to trigger other jobs, evaluate conditions, and injecting environmental parameters. each step in the build can write output, all output is redirected to the console output.
The build artifacts are files\folders in your workspace that are created during the build (log files, test reports, each). files from your workspace on the slave are being transferred to the Master Jenkins when you archive the artifacts.
If this is your Jenkins server then you can access the job configuration and see which files you're transferring to the master. it'll be a step under post-build section.

Copying files from one directory to another in jenkins

I'm trying to move my test results onto a public webpage.
I set up a "Post-build action" > "Post build task" to execute a script.
The script is:
cp -r /var/lib/jenkins/jobs/instrumentation-tests/htmlreports/HTML_Report/ /var/www/html/test/
Jenkins outputs: cp: directory /var/www/html/test does not exist
If I'm logged in as user jenkins on the linux machine running jenkins, I can navigate to the source and SEE that there are files there currently. I can navigate to the destination and see that it DOES exist.
Also, I tried running that command from the terminal as the jenkins user, and the cp completed successfully.
As you mention in the comments, your test results are being generated during a build on a slave machine. Therefore you're trying to copy the files to /var/www on the slave, not the Jenkins master server.
There are a few different ways you could solve this:
Ensure that the build happens on the master server.
You can do this by choosing "Restrict where this project can be run" on the job configuration page, and entering "master" in the text field.
This ensures that your file copying will work at the end of a build, assuming that the Jenkins user has write permissions.
Use the Publish over SSH plugin to publish the files directly to /var/www on the Jenkins master, from any other machine.
This has the advantage that it will work, no matter which Jenkins build machine the build takes place on.
You could also split up the job into two parts: one job to run the tests and generate the results, and another job to publish the test results.
The first job could run on any machine, and would save the generated HTML files using the "Archive the artifacts" post-build action. It would then start the second job — via the "Build other jobs" post-build action — in order to do the publishing.
The second job could use either of the above approaches: either publish using SSH, or ensure that it runs on the master and use a simple shell step with cp.
In both cases, you would use the Copy Artifact plugin to copy the archived HTML files from the upstream build.

Jenkins - Copy build log from master to a shared drive

Can someone direct me here? I have a simple job configured in Jenkins on a WINDOWS environment (master and all slaves running on windows) and the job is supposed to run on a particular slave. When you build the job, the build log ( log.log) gets stored in ” %JENKINS_HOME%\jobs\\builds\%BUILD_NUMBER%\” on the master.
I do have a Jenkins workspace (which is required when you add a slave node) set on the slave for this job–where nothing gets stored when the job runs.
With this scenario, I would like to copy the build log (log.log file that’s available on the master) to a share drive. Please advise me the way to get this done. I have tried few plugins “Copy to slave”, “Copy Artifact Plugin” and ArtifactDeployer Plugin…I could not get them working to meet what I need.
Use a second build action with the execute batch option. Put the copy command there to copy the log to another location.
The following command kind-of works:
curl ${BUILD_URL}consoleFull -o ${TargetDir}/Log.txt
where
TargetDir="${WORKSPACE}/Directory/target"
BUILD_URL and WORKSPACE are set by Jenkins. Unfortunately Jenkins doesn't copy the whole log. I've tried consoleText and gotten the same result: partial logs files. :-(

How to publish logs in Jenkins?

I am trying to use Jenkins to run a script on Linux. The script will run on a Linux slave, generate some log files in Jenkins working directory and tar file in a dedicated place on the slave build server.
Is there a way to publish these log files and tar file to the build result, so they can be inspected/downloaded from the build result page.
Use the "Archive the artfacts" option in the post-build steps of your Jenkins job configuration and specify the paths to the files you want to save. They will then be linked on the build page under "Last successful artifacts".
"Archive the artfacts" is one option, or you could copy the logs to %JenkinsDir%\%BUILD_ID%\archive folder as a post build action. Then you can see them as build artifacts.
You may need Log Parser plugin for extracting info from log

Resources