Files not appearing in Jenkins workspace - jenkins

I have an npm script that basically executes some unit tests with Jest and then generates a test-results.xml file in a dist/ folder. This is executed within a deploy.sh script that basically has a npm run test line in it that kicks off the test task.
When Jenkins runs my code, however, I can see that the tests are passing in the Jenkins console, but for some reason Jenkins can't see the test-results.xml file in the workspace. Hence, I get this error:
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
It's weird because I SSH'd into my server and can clearly see that my test script generated a test-results.xml file under dist/ folder, but for some reason the entire dist/ folder and everything in it is conspicuously absent from my Jenkins workspace.

This question was resolved in question comments, but for future reference and other in similar situations:
Make sure that you are looking at the same place as Jenkins is. Jenkins always resolves the pattern provided in the Public JUnit test result report relative the workspace root.
For freestyle jobs or node steps in pipeline jobs, the location of the workspace root is printed on the console output, look for:
Building in workspace <jenkins_root>\workspace\<job_name>
or
Building remotely on Agent42 in workspace <path_to_workspaces>/workspace/<job_name>

Related

Subsequent build job in Jenkins does not find workspace file

I have separated my build tasks in several jobs. The following is a simplified structure.
The basic jobs are:
compile
quick-tests
full-tests-part-1
full-tests-part-2
Additional jobs are:
full-tests
full-build
Each job is configured to accept a workspace parameter to allow all jobs to be executed on the same code (workspace). This is passed from any calling job. Besides, all jobs are running on a slave node.
Job full-tests is configured to bundle the "full tests". Therefore it uses the build step Trigger/call builds on other projects with projects full-tests-part-1, full-tests-part-2.
Job full-build is configured to bundle the build pipeline. Therefore it uses the build step Trigger/call builds on other projects with projects compile, full-tests.
Job compile checks out the Git repository and compiles the code. Afterwards it starts the quick tests. Therfore it uses the post build action Trigger parametrized build on other projects with project quick-tests.
All compilation and test runs are triggered by Ant scripts.
When I trigger the full-build job, the following job sequence results:
full-build
compile (triggers quick-tests)
full-tests
full-tests-part-1
full-tests-part-2
quick-tests
The problem is, that the "full tests" are failing, whereas compile and quick-tests succeed. Both, the full and the quick tests, use the same build.xml in the same workspace, but the "full tests" complains.
Quick tests:
Buildfile: J:\jenkins-slave\workspace\full-build\272\project-path\build.xml
Full tests:
ERROR: Unable to find build script at J:\jenkins-slave\workspace\full-build\272\project-path\build.xml
Does anyone know whether there is a difference in "seeing" the workspace files depending on whether the job is part of the build (triggered as build step) or not (triggered as post build action).
If anything is unclear, please let me know.

Jenkins Copy Artifact - does not copy any files

I am using copy artifact 1.46 in Jenkins 2.263.4 and want to copy a file from one job to another. However, it fails to do so. The error is always:
ERROR: Failed to copy artifacts from TestPack with filter: **
Have tried this with both a scripted pipeline job and a freestyle one, on both Windows and Centos, but same result. I know it has found the job, because I get an error if the job name if wrong. The job I want to copy from only has a single text file in its root directory.
My pipeline script is:
node ("${env.Node}") {
stage('dodeploy') {
copyArtifacts(projectName: 'TestPack');
}
}
I have tried copyArtifacts with and without a filter and with and without a target. In the freestyle project I tried similar settings settings, but get exactly the same error.
Feel I must be missing something obvious, but cannot see what.
Turns out that I was not interpreting the 'Artifacts' part of 'copyArtifacts' literally enough. It looks as though copyArtifacts can only copy files that have previously been archived in a post build step (or pipeline stage).

Optimized alternative to stashing files in jenkins

The jenkins pipeline currently does a build and deploy, stashes some files, unstashes them and runs end to end tests on these files as so:
// build and deploy code
stash([
name: 'end-to-end-tests',
includes: <a bunch of files>
])
unstash('end-to-end-tests')
// code to run tests using npm run test:end-to-end-tests
In the interest of speeding up this pipeline, is there a way to get around the stash? I need end-to-end-tests in order to run my tests with the appropriate npm command later on, but how can I use this without stashing (if possible)?

Copy file from Jenkins master to slave in Pipeline

I have some windows slave at my Jenkins so I need to copy file to them in pipeline. I heard about Copy To Slave and Copy Artifact plugins, but they doesn't have pipeline syntax manual. So I don't know how to use them in pipeline.
Direct copy doesn't work.
def inputFile = input message: 'Upload file', parameters: [file(name: 'parameters.xml')]
new hudson.FilePath(new File("${ENV:WORKSPACE}\\parameters.xml")).copyFrom(inputFile)
This code returns and error:
Caused: java.io.IOException: Failed to copy /var/lib/jenkins/jobs/_dev/jobs/(TEST)job/builds/107/parameters.xml to d:\Jenkins\workspace\_dev\(TEST)job\parameters.xml
Is there any way to copy file from master to slave in Jenkins Pipeline?
As I understand copyFrom is executed on your Windows node, therefore the source path is not accessible.
I think you want to look into the stash/unstash steps (Jenkins Pipeline: Basic Steps), which work across different nodes. Also this example might be helpful.
Pipeline DSL context runs on master node even that your write node('someAgentName') in your pipeline.
Try to use stash/unstash, but it is bad for large files.
Try External Workspace Manager Plugin. It has
pipelines steps and good for large files.
Try to use an intermediate storage. archive() and sh("wget $url") will be helpful.
If the requirement is to copy an executable to the test slave and to publish the test results, this is easy to do without the Copy to Slave plugin.
A shared folder should be created on each test slave (normal Windows shared folder).
After build: Build script copies the executable to the shared directory on each slave. A simple batch script using copy command is sufficient for this.
stage ('Copy to slaves') {
steps {
bat 'call "copy-to-slave.bat"'
}
}
During test: The test script copies the executable to another directory and runs it.
After test: Post-build action "Publish Robot Framework test results" can be used to report the test results. It is not necessary to copy the test result files back to the master first.
I recommend on Pipeline: Phoenix AutoTest plugin
Jenkins plugin website:
https://plugins.jenkins.io/phoenix-autotest/#documentation
GitHub repository of plugin:
https://github.com/jenkinsci/phoenix-autotest-plugin

how to set up /configure test cases before triggering in jenkins

After the build is passed for source code, some .jar files are created.
Those jar files have to be put in specific path before triggering relevant testcases in Jenkins.
In a short,
How to configure/set up the test cases after the successful build and before triggering them in Jenkins?
Have 1 job to build your code.
Add a post exec command to this job to move the jar files to the correct path
After this build job is finished have it trigger a second job that does only the tests.

Resources