jenkins-infra / jenkins.io

A static site for the Jenkins automation server
https://jenkins.io
Other
359 stars 1.3k forks source link

Invalid Agent Type "docker" in Using Docker with Pipeline Example #7870

Open ahmadzeinalwafi opened 1 month ago

ahmadzeinalwafi commented 1 month ago

Description

The official Jenkins documentation provides a pipeline example using agent { docker { image '...' } } on tutorial Using multiple containers Using Docker with Pipeline , but when executed, it fails with the following error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 6: Invalid agent type "docker" specified. Must be one of [any, label, none] @ line 6, column 17.
                   docker { image 'maven:3.9.9-eclipse-temurin-21-alpine' }
                   ^

WorkflowScript: 14: Invalid agent type "docker" specified. Must be one of [any, label, none] @ line 14, column 17.
                   docker { image 'node:22.13.1-alpine3.21' }
                   ^

2 errors

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1107)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:624)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293)
    at PluginClassLoader for script-security//org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox$Scope.parse(GroovySandbox.java:163)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:190)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:175)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:652)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:598)
    at PluginClassLoader for workflow-job//org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:343)
    at hudson.model.ResourceController.execute(ResourceController.java:101)
    at hudson.model.Executor.run(Executor.java:446)
Finished: FAILURE

Steps to Reproduce

Copy and paste the following example into a Jenkins pipeline job:

pipeline {
    agent none
    stages {
        stage('Back-end') {
            agent {
                docker { image 'maven:3.9.9-eclipse-temurin-21-alpine' }
            }
            steps {
                sh 'mvn --version'
            }
        }
        stage('Front-end') {
            agent {
                docker { image 'node:22.13.1-alpine3.21' }
            }
            steps {
                sh 'node --version'
            }
        }
    }
}

Run the pipeline

Observe the error message about the invalid agent type docker.

Expected Behavior

The pipeline should execute successfully, pulling the specified Docker images and running the steps within them.

Actual Behavior

Jenkins throws an error indicating that docker is not a valid agent type, suggesting only [any, label, none] are supported.

Environment Details

Jenkins Image Version DockerHub

jenkins/jenkins:lts-jdk17

Docker Plugin Installed

No

Jenkins Running Mode

Docker Compose

Possible Cause

The documentation may be outdated or missing a required plugin. Either the documentation should be corrected, or the error message should provide guidance on the necessary plugin.

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

Are you interested in contributing a fix?

No response

MarkEWaite commented 1 month ago

Thanks for reporting the issue. The documentation assumes the user has installed the Pipeline plugins (offered through the setup wizard) and the Docker Pipeline plugin

Since you note that you are running from Docker compose, then the examples that use docker are not expected to work. When the Jenkins controller is run inside a container, it is generally a bad security practice to allow that controller to start additional containers. The additional instructions added to the page would need to note for users that if they are running the controller inside a container, then they will need to configure one or more agents that are able to run a container.