如何在 Jenkins 多分支管道中拉取 docker 个图像并启动容器?

How to pull docker images in Jenkins multi-branch pipeline and spin up container?

我正在编写一个 Jenkinsfile 来为多分支管道创建构建,并编写 docker/docker 管道插件来在 Jenkins 中启动 docker 容器。我有一个图像,我想用它来构建 docker 容器。我需要从某个 URL 说:docker.abc.com、运行 容器中提取此图像,然后在容器内执行所有 Jenkins 操作。我目前收到以下错误:

Jenkins does not seem to be running inside a container

我的代码看起来像这样:

node {
    try {
        // set working directory
        dir(working directory here){
            stage(main){
                checkout scm
                docker.image("docker.abc.com/def:latest").inside{
                    // do Jenkins stuff
                }
            }
        }
    }
    catch {
        // catch error and send notification
    }
}

几天前我解决了这个问题。我的代码结构(我不能分享确切的代码,抱歉):

node {
    try {
        // set working directory
        dir(working directory here){
            stage(main){
                // get docker image
                // defined a docker command here that runs the container, clones git repository inside it and uses makefile to build the project
                // ran the docker command in a shell script
            }
        }
    }
    catch {
        // catch error and send notification
    }
}