0
0
Jenkinsdevops~10 mins

Environment directive 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 define an environment variable named GREETING with value 'Hello'.

Jenkins
pipeline {
  agent any
  environment {
    GREETING = [1]
  }
  stages {
    stage('Example') {
      steps {
        echo "${GREETING}, World!"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"World"
B"Hello"
C'Hello World'
DHello
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the value causes syntax errors.
Using unquoted words is invalid in environment directive.
2fill in blank
medium

Complete the code to set an environment variable PATH_EXT to '/usr/local/bin'.

Jenkins
pipeline {
  agent any
  environment {
    PATH_EXT = [1]
  }
  stages {
    stage('Show Path') {
      steps {
        sh 'echo $PATH_EXT'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A/usr/local/bin
B/usr/local/bin/
C'/usr/local/bin'
D"/usr/local/bin"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the path string.
Adding trailing slash when not intended.
3fill in blank
hard

Fix the error in the environment directive to correctly set JAVA_HOME to '/usr/lib/jvm/java-11-openjdk'.

Jenkins
pipeline {
  agent any
  environment {
    JAVA_HOME = [1]
  }
  stages {
    stage('Build') {
      steps {
        sh 'echo $JAVA_HOME'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"/usr/lib/jvm/java-11-openjdk"
B/usr/lib/jvm/java-11-openjdk
C'/usr/lib/jvm/java-11-openjdk'
D/usr/lib/jvm/java-11-openjdk/
Attempts:
3 left
💡 Hint
Common Mistakes
Missing quotes around the path causes syntax errors.
Using single quotes sometimes works but double quotes are safer.
4fill in blank
hard

Fill both blanks to set environment variables USER_NAME to 'admin' and USER_ROLE to 'developer'.

Jenkins
pipeline {
  agent any
  environment {
    USER_NAME = [1]
    USER_ROLE = [2]
  }
  stages {
    stage('Print') {
      steps {
        echo "User: ${USER_NAME}, Role: ${USER_ROLE}"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"admin"
B"user"
C"developer"
D"guest"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the values for USER_NAME and USER_ROLE.
Forgetting quotes around the values.
5fill in blank
hard

Fill all three blanks to set environment variables APP_ENV to 'production', APP_VERSION to '1.2.3', and DEBUG_MODE to 'false'.

Jenkins
pipeline {
  agent any
  environment {
    APP_ENV = [1]
    APP_VERSION = [2]
    DEBUG_MODE = [3]
  }
  stages {
    stage('Info') {
      steps {
        echo "Environment: ${APP_ENV}, Version: ${APP_VERSION}, Debug: ${DEBUG_MODE}"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"development"
B"1.2.3"
C"false"
D"production"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted values causes errors.
Mixing up the variable values.