0
0
Jenkinsdevops~10 mins

Build history and logs in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AcurrentBuild.number
Bbuild.number
ClastBuild.number
Dbuilds.number
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build.number' which is undefined in pipeline context.
2fill in blank
medium

Complete 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'
Abuild.log
B**/build.log
Clogs/build.log
D**/logs/*.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single file name which may not match all logs.
3fill in blank
hard

Fix 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'
Aduration
BdurationInMillis
CtimeMillis
DbuildDuration
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'duration' which is not a property of currentBuild.
4fill in blank
hard

Fill 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'
A"ERROR"
Berrors
C"WARNING"
Derrors.trim()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'WARNING' instead of 'ERROR' for filtering.
5fill in blank
hard

Fill 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'
Abuild.number
Bbuild.result.toString()
C10
Dbuild.status
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build.status' which is not a valid property.