Run stage in a Docker Agent


pipeline {
    agent none
    stages {
        stage('Build in Docker') {
            agent {
                docker { image 'alpine:latest' }
            }
            steps {
                sh 'echo "Inside Alpine Container"'
                sh 'cat /etc/os-release'
            }
        }
    }
}


but it gave error

Started by user Admininsrtaor
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 'alpine:latest' }
                   ^

That error means Jenkins isn't recognizing agent { docker { ... } } as a valid declarative agent type.
This happens when the Docker Pipeline plugin isn’t installed/updated or you're using a syntax that your Jenkins version doesn’t support.


Correct Declarative Pipeline Example (requires Docker Pipeline Plugin):

pipeline { agent none stages { stage('Build in Docker') { agent { docker { image 'alpine:latest' } } steps { sh 'echo "Inside Alpine Container"' sh 'cat /etc/os-release' } } } }

If that still throws the same error, you’re on a Jenkins version where Docker agent must be inside agent { docker } without nested block or plugin missing.

First verify the plugin

Dashboard → Manage Jenkins → Manage Plugins → Installed/Available
Search for:

Docker Pipeline

Install & restart Jenkins if missing.


If using an older version, try simplified syntax:

pipeline { agent none stages { stage('Build in Docker') { agent { docker 'alpine:latest' } steps { sh 'echo "Inside Alpine Container"' } } } }

If Docker agent still doesn’t work, alternative scripted solution:

node { docker.image('alpine:latest').inside { sh 'echo "Inside Alpine Container"' sh 'cat /etc/os-release' } }

Summary

CauseFix
Invalid agent type "docker".        Install Docker Pipeline plugin
Older Jenkins syntaxUse agent { docker 'img' } or scripted pipeline
Master doesn’t run jobsMust run on a node with Docker installed
Distributed by Gooyaabi Templates | Designed by OddThemes