0
0
Jenkinsdevops~10 mins

Agent 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 specify the agent for the Jenkins pipeline.

Jenkins
pipeline {
  agent [1]
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Anone
Blabel
Cdocker
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'none' disables the agent, which is not intended here.
Using 'docker' requires additional configuration.
2fill in blank
medium

Complete the code to specify a label for the Jenkins agent.

Jenkins
pipeline {
  agent {
    label '[1]'
  }
  stages {
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alinux
Bany
Cdocker
Dwindows
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'any' ignores the label requirement.
Using 'docker' is not a label but a different agent type.
3fill in blank
hard

Fix the error in the agent directive to use a Docker container.

Jenkins
pipeline {
  agent {
    docker [1]
  }
  stages {
    stage('Deploy') {
      steps {
        echo 'Deploying...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A'node:14'
Bnode:14
Cnode14
D'node14'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes causes syntax errors.
Using incorrect image names without colon and version.
4fill in blank
hard

Fill both blanks to specify a Docker agent with a custom label.

Jenkins
pipeline {
  agent {
    docker {
      image [1]
      label [2]
    }
  }
  stages {
    stage('Integration') {
      steps {
        echo 'Running integration tests...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A'python:3.9'
B'node:16'
C'linux'
D'docker-agent'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up image and label values.
Omitting quotes around strings.
5fill in blank
hard

Fill all three blanks to define a Jenkins pipeline with a Kubernetes agent specifying the YAML file, label, and default container.

Jenkins
pipeline {
  agent {
    kubernetes {
      yamlFile [1]
      label [2]
      defaultContainer [3]
    }
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building in Kubernetes...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A'pod.yaml'
B'k8s-agent'
C'jnlp'
D'agent.yaml'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong YAML file names.
Confusing label and container names.
Omitting quotes around strings.