Complete the code to define a Jenkins pipeline stage that archives build artifacts.
stage('Archive Artifacts') { steps { [1] 'build/output/*.jar' } }
The archiveArtifacts step in Jenkins saves build outputs so they can be accessed later.
Complete the code to upload an artifact to a Nexus repository using a shell command in Jenkins.
stage('Upload Artifact') { steps { sh 'curl -v -u user:pass -X POST [1]' } }
The curl command uploads the artifact file to the Nexus repository using the -F flag for form data.
Fix the error in the Jenkins pipeline snippet that tries to download an artifact but uses the wrong step.
stage('Download Artifact') { steps { [1] 'curl -O http://nexus.example.com/repository/maven-releases/app.jar' } }
The sh step runs shell commands. To download an artifact, you can use curl inside sh. There is no built-in downloadArtifacts step.
Fill both blanks to create a Jenkins pipeline snippet that saves and then cleans up artifacts.
stage('Save and Clean') { steps { [1] 'dist/*.zip' [2]() } }
archiveArtifacts saves the files, and deleteDir cleans the workspace directory.
Fill all three blanks to define a Jenkins pipeline that builds, archives, and uploads an artifact.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'mvn clean package'
}
}
stage('Archive') {
steps {
[2] 'target/*.jar'
}
}
stage('Upload') {
steps {
[3] 'curl -v -u user:pass -X POST "http://nexus.example.com/repository/maven-releases/" -F "file=@target/app.jar"'
}
}
}
}Use sh to run the build command, archiveArtifacts to save the jar, and sh again to upload with curl.