0
0
Jenkinsdevops~10 mins

Docker agents for isolation 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 Docker agent in a Jenkins pipeline.

Jenkins
pipeline {
  agent {
    docker {
      image '[1]'
    }
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building inside Docker container'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aubuntu:latest
Bnodejs:14
Calpine:3.12
Dpython:3.8
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid or misspelled image name.
Omitting the image tag (like :latest).
2fill in blank
medium

Complete the code to run a shell command inside the Docker agent.

Jenkins
pipeline {
  agent {
    docker {
      image 'python:3.8'
    }
  }
  stages {
    stage('Test') {
      steps {
        sh '[1]'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Apython --version
Bpip install requests
Cecho Hello World
Dls -l
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands that require prior installation.
Using commands unrelated to the container's environment.
3fill in blank
hard

Fix the error in the Docker agent declaration to correctly specify the Docker image.

Jenkins
pipeline {
  agent {
    docker {
      image [1]
    }
  }
  stages {
    stage('Deploy') {
      steps {
        echo 'Deploying application'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"nginx:latest"
Bnginx:latest
C'nginx:latest'
Dnginx_latest
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the image name.
Using invalid image names.
4fill in blank
hard

Fill both blanks to define a Docker agent with a custom label and reuse the same image in a stage.

Jenkins
pipeline {
  agent {
    docker {
      image [1]
      label [2]
    }
  }
  stages {
    stage('Build') {
      agent {
        docker {
          image 'myapp:latest'
        }
      }
      steps {
        echo 'Building inside Docker'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A'myapp:latest'
B'docker-agent'
C'ubuntu:20.04'
D'build-node'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted strings for image or label.
Mismatching image names between agent and stage.
5fill in blank
hard

Fill all three blanks to create a Docker agent with arguments, reuse the image, and run a command inside the container.

Jenkins
pipeline {
  agent {
    docker {
      image [1]
      args [2]
    }
  }
  stages {
    stage('Test') {
      steps {
        sh '[3]'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A'node:16'
B'-u root:root'
Cnpm test
D'--privileged'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the image or args values.
Using incorrect shell commands.