Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the last build number in Jenkins pipeline.
Jenkins
echo "Last build number is: [1]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build.number' which is undefined in pipeline context.
✗ Incorrect
In Jenkins pipeline, currentBuild.number gives the current build number.
2fill in blank
mediumComplete the code to archive the build logs as artifacts in Jenkins pipeline.
Jenkins
archiveArtifacts artifacts: '[1]', fingerprint: true
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single file name which may not match all logs.
✗ Incorrect
The pattern **/logs/*.log archives all log files inside any 'logs' folder.
3fill in blank
hardFix the error in the code to get the build duration in seconds.
Jenkins
def duration = currentBuild.[1] / 1000
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'duration' which is not a property of currentBuild.
✗ Incorrect
currentBuild.durationInMillis holds the build duration in milliseconds.
4fill in blank
hardFill both blanks to filter build logs for errors and save them.
Jenkins
def errors = sh(script: 'grep [1] build.log', returnStdout: true).trim() writeFile file: 'errors.txt', text: [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'WARNING' instead of 'ERROR' for filtering.
✗ Incorrect
Use grep "ERROR" to find error lines and save the variable errors to file.
5fill in blank
hardFill all three blanks to create a map of build numbers to their result status.
Jenkins
def buildResults = [[1]: [2] for build in currentBuild.rawBuild.project.builds if build.number > [3]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build.status' which is not a valid property.
✗ Incorrect
Use build.number as key, build.result.toString() as value, and filter builds with number greater than 10.