According to Jenkins Pipeline Docs, I should be able to use pipeline steps while working with Docker. However, "archiveArtifacts" does not appear to work:
def container = docker.image("some_image")
container.inside {
sh 'date > /tmp/test.txt'
sh 'cat /tmp/test.txt' //works, shows file
def fileContents = readFile '/tmp/test.txt' //works
echo "Contents: ${fileContents}" //works, shows file
archiveArtifacts '/tmp/*.txt' //FAILS
}
"ERROR: No artifacts found that match the file pattern "/tmp/*.txt". Configuration error?".
Things I've tried:
Any suggestions on archiving files generated in a Docker container?
PS: I opened a bug report... It looks like archiveArtifacts will only work on files in $WORKSPACE in docker containers.
To spin up the Alpine-Jenkins container and give it access to Docker, use docker run. If you are interested in how the image is configured, be sure to look at the liatrio/alpine-jenkins repository’s Dockerfile for an overview. 5. Wait for the image to download and run. Afterward, Jenkins should be visible in a web browser at localhost:8080. 1.
The image will be built using the Dockerfile in the current directory, and it will be tagged with my Docker Hub username and repository as the latest image. sh 'docker build -t shanem/spring-petclinic:latest .' 2. Ensure the image was successfully built (it should be if the updated Jenkinsfile is pushed up to GitHub and the job is run again).
First let’s understand what is archieve file in jenkins and why we need this. Archive is how to save files outside workspace. You can clean your workspace, run other builds and the file archieved is safe. Ex: You build the jar/html/js file, this file is important for deploy. After other build, your file is replaced or can be removed.
Enter your Docker Hub credentials. Make sure to use only your Docker Hub username and not your email address. These credentials will be referenced in the Jenkinsfile using their ID value. Hit OK. Finally, the last stage will be added to our Jenkinsfile that pushes our image up to Docker Hub.
You seem to have found the solution as reported in the same Jira ticket so I'll post here for everyone:
this works fine:
def image = docker.image("alpine") image.inside { sh 'date > /tmp/test.txt' sh "cp /tmp/test.txt ${WORKSPACE}" archiveArtifacts 'test.txt' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With