0
0
Jenkinsdevops~10 mins

Pipeline utility functions 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 read a file content using pipeline utility function.

Jenkins
def content = readFile [1] 'example.txt'
Drag options to blanks, or click blank then click option'
A(
B'('
C[
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Forgetting to add parentheses after the function name.
2fill in blank
medium

Complete the code to write text to a file using pipeline utility function.

Jenkins
writeFile [1] file: 'output.txt', text: 'Hello World'
Drag options to blanks, or click blank then click option'
A'('
B[
C(
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for named arguments.
Using curly braces which are for closures, not maps.
3fill in blank
hard

Fix the error in the code to archive artifacts correctly.

Jenkins
archiveArtifacts [1] 'build/output/*.jar'
Drag options to blanks, or click blank then click option'
A[
B(
C'('
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Passing the path as a plain string without a key.
4fill in blank
hard

Fill both blanks to create a map of file sizes for files larger than 1000 bytes.

Jenkins
def sizes = [file.name: [1] for file in files if file.length() [2] 1000]
Drag options to blanks, or click blank then click option'
Afile.length()
B>
C<
Dfile.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using file name instead of file length for the map value.
Using less than operator instead of greater than.
5fill in blank
hard

Fill all three blanks to filter environment variables starting with 'BUILD_' and map their names to values.

Jenkins
def buildVars = [[1]: env.[2] for [3] in env.getEnvironment().keySet() if [3].startsWith('BUILD_')]
Drag options to blanks, or click blank then click option'
Avar
CvarName
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for key and value.
Using 'var' instead of 'varName' which is more descriptive.