Bird
Raised Fist0
Jenkinsdevops~20 mins

Copying artifacts between jobs in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Artifact Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Jenkins pipeline snippet?

Consider this Jenkins pipeline stage that copies artifacts from a previous job named BuildJob:

stage('Copy Artifacts') {
  steps {
    copyArtifacts(projectName: 'BuildJob', selector: lastSuccessful())
  }
}

What happens when this stage runs?

Jenkins
stage('Copy Artifacts') {
  steps {
    copyArtifacts(projectName: 'BuildJob', selector: lastSuccessful())
  }
}
ACopies artifacts from the last successful build of 'BuildJob' into the current workspace.
BTriggers 'BuildJob' to run and copies its artifacts immediately.
CCopies artifacts from the current job to 'BuildJob'.
DFails because 'copyArtifacts' requires a build number, not a selector.
Attempts:
2 left
💡 Hint

Think about what lastSuccessful() means in Jenkins.

❓ Configuration
intermediate
2:00remaining
Which Jenkinsfile snippet correctly copies artifacts from a specific build number?

You want to copy artifacts from build number 42 of the job named TestJob. Which snippet does this correctly?

AcopyArtifacts(projectName: 'TestJob', selector: build('42'))
BcopyArtifacts(projectName: 'TestJob', buildNumber: 42)
CcopyArtifacts(projectName: 'TestJob', selector: specific('42'))
DcopyArtifacts(projectName: 'TestJob', selector: specificBuild(42))
Attempts:
2 left
💡 Hint

Look for the correct selector method for a specific build number.

❓ Troubleshoot
advanced
2:00remaining
Why does this Jenkins pipeline fail to copy artifacts?

Given this pipeline snippet:

stage('Copy') {
  steps {
    copyArtifacts(projectName: 'NonExistentJob', selector: lastSuccessful())
  }
}

The pipeline fails with an error about missing artifacts. What is the most likely cause?

AThe job 'NonExistentJob' does not exist or has no successful builds.
BThe <code>copyArtifacts</code> step requires a build number, not a selector.
CThe pipeline workspace is not writable.
DThe <code>copyArtifacts</code> plugin is not installed.
Attempts:
2 left
💡 Hint

Check if the source job exists and has successful builds.

🔀 Workflow
advanced
2:30remaining
What is the correct order to copy artifacts between jobs in a multi-stage pipeline?

Arrange these steps in the correct order to copy artifacts from a build stage to a deploy stage within the same pipeline:

A4,2,1,3
B1,4,2,3
C2,1,4,3
D4,1,2,3
Attempts:
2 left
💡 Hint

Think about preparing workspace, building, copying, then deploying.

✅ Best Practice
expert
2:00remaining
Which practice ensures reliable artifact copying between Jenkins jobs?

Choose the best practice to avoid failures when copying artifacts between jobs in Jenkins pipelines.

ACopy artifacts without specifying a build selector to get the latest.
BAlways archive artifacts in the source job before copying them.
CUse workspace sharing instead of artifact copying.
DDisable artifact archiving to speed up the pipeline.
Attempts:
2 left
💡 Hint

Think about what makes artifacts available for copying.

Practice

(1/5)
1. What is the main purpose of using the copyArtifacts step in Jenkins?
easy
A. To compile source code in a Jenkins job
B. To delete artifacts after a build completes
C. To trigger a new Jenkins job automatically
D. To copy files from one Jenkins job to another

Solution

  1. Step 1: Understand the copyArtifacts step

    The copyArtifacts step is designed to transfer files (artifacts) from one Jenkins job to another.
  2. Step 2: Identify the main use case

    This step helps share build outputs between jobs without rebuilding, enabling reuse of files.
  3. Final Answer:

    To copy files from one Jenkins job to another -> Option D
  4. Quick Check:

    copyArtifacts = copy files between jobs [OK]
Hint: copyArtifacts copies files between jobs, not triggers or deletes [OK]
Common Mistakes:
  • Confusing copyArtifacts with job triggers
  • Thinking it deletes files instead of copying
  • Assuming it compiles code
2. Which of the following is the correct syntax to copy artifacts from a job named BuildJob in a Jenkins pipeline script?
easy
A. copyArtifacts(projectName: 'BuildJob')
B. copyArtifacts('BuildJob')
C. copyArtifacts job: 'BuildJob'
D. copyArtifacts from: 'BuildJob'

Solution

  1. Step 1: Recall the correct syntax for copyArtifacts

    The correct syntax uses named parameters, with projectName specifying the source job.
  2. Step 2: Match the syntax to the options

    copyArtifacts(projectName: 'BuildJob') uses copyArtifacts(projectName: 'BuildJob'), which is the correct form in pipeline scripts.
  3. Final Answer:

    copyArtifacts(projectName: 'BuildJob') -> Option A
  4. Quick Check:

    Use named parameter projectName in copyArtifacts [OK]
Hint: Use named parameter projectName: 'JobName' in copyArtifacts [OK]
Common Mistakes:
  • Using positional arguments instead of named parameters
  • Using incorrect keywords like job or from
  • Missing parentheses or quotes
3. Given the following Jenkins pipeline snippet, what files will be copied?
copyArtifacts(projectName: 'BuildJob', filter: '**/*.jar')
medium
A. Only files with .jar extension from BuildJob artifacts
B. All files from BuildJob workspace
C. Only files named exactly 'filter' from BuildJob
D. No files will be copied due to syntax error

Solution

  1. Step 1: Understand the filter parameter

    The filter parameter uses Ant-style patterns to select files. '**/*.jar' means all .jar files in any folder.
  2. Step 2: Determine which files are copied

    Only artifact files matching the pattern '*.jar' from the 'BuildJob' are copied, not all files.
  3. Final Answer:

    Only files with .jar extension from BuildJob artifacts -> Option A
  4. Quick Check:

    filter '**/*.jar' copies only .jar files [OK]
Hint: filter '**/*.ext' copies only files with that extension [OK]
Common Mistakes:
  • Assuming all files copy without filter
  • Thinking filter is a filename, not a pattern
  • Believing syntax causes error here
4. You wrote this snippet to copy artifacts but it fails:
copyArtifacts(projectName: BuildJob)
What is the likely cause of the failure?
medium
A. copyArtifacts does not accept projectName parameter
B. Missing quotes around the job name 'BuildJob'
C. The job BuildJob does not exist
D. copyArtifacts requires a filter parameter

Solution

  1. Step 1: Check syntax for projectName parameter

    In pipeline scripts, string values must be quoted. Missing quotes cause syntax errors.
  2. Step 2: Identify the error cause

    Since BuildJob is unquoted, Jenkins treats it as a variable, causing failure if undefined.
  3. Final Answer:

    Missing quotes around the job name 'BuildJob' -> Option B
  4. Quick Check:

    Job names must be quoted strings [OK]
Hint: Always quote job names in copyArtifacts [OK]
Common Mistakes:
  • Forgetting quotes around job names
  • Assuming filter is mandatory
  • Ignoring existence of source job
5. You want to copy only the latest successful build's output.zip artifact from job PackageJob to your current job. Which snippet correctly does this?
hard
A. copyArtifacts(projectName: 'PackageJob', selector: latest(), filter: 'output.zip')
B. copyArtifacts(projectName: 'PackageJob', filter: 'output.zip')
C. copyArtifacts(projectName: 'PackageJob', selector: lastSuccessful(), filter: 'output.zip')
D. copyArtifacts(projectName: 'PackageJob', selector: lastCompleted(), filter: 'output.zip')

Solution

  1. Step 1: Understand selecting the build to copy from

    The selector parameter chooses which build's artifacts to copy. lastSuccessful() picks the latest successful build.
  2. Step 2: Verify filter and selector usage

    copyArtifacts(projectName: 'PackageJob', selector: lastSuccessful(), filter: 'output.zip') uses selector: lastSuccessful() and filters for 'output.zip', matching the requirement exactly.
  3. Final Answer:

    copyArtifacts(projectName: 'PackageJob', selector: lastSuccessful(), filter: 'output.zip') -> Option C
  4. Quick Check:

    Use selector lastSuccessful() to copy latest successful build [OK]
Hint: Use selector lastSuccessful() to get latest successful build artifacts [OK]
Common Mistakes:
  • Using selector latest() which is invalid
  • Omitting selector and copying from last build regardless of status
  • Using lastCompleted() which may include failed builds
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard