在jenkins中作为连续集成工具的带有入口点的正式expressif映像容器不能正确启动

6ojccjat  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(164)

我正在处理一个使用expressif的项目,并使用docker在我的机器上构建它,我执行以下操作:
--entrypoint=''
我想详细说明一个声明性管道,并且我想执行与上面的命令等效的命令。我实现它的方式基于其他工作的例子,以及下面的日志结果。
我不明白为什么在'steps'块中传递这些'idf.py build'参数的方法不起作用。有人有什么想法吗?
阅读日志和做一些谷歌搜索,我相信这是Jenkins插件不能处理的命令,因为图像使用的入口点功能。

我的管道:

pipeline {
    agent any

    environment {
        PROJ_NAME = 'test'
    }
    stages {
        stage('Checkout') {
            steps {
                git url: 'ssh://git@bitbucket.org/john/iot-project.git'
            }
        }
        stage('Build') {
            agent {
                docker {
                    image 'espressif/idf:v4.2.2'
                    args '--rm -v $PWD:/project -w /project'
                    reuseNode true
                }
            }
            steps{
                sh 'idf.py build'
            }
        }
    }
}

错误代码段:

[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 1000:1000 --rm -v $PWD:/project -w /project -w /var/lib/jenkins/workspace/iot-project-TEST -v /var/lib/jenkins/workspace/iot-project-TEST:/var/lib/jenkins/workspace/iot-project-TEST:rw,z -v /var/lib/jenkins/workspace/iot-project-TEST@tmp:/var/lib/jenkins/workspace/iot-project-TEST@tmp:rw,z -e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********-e********espressif/idf:v4.2.2 cat
$ docker top 81920a1146eabe9bf5c08339a682d81ac23777de0421895e1184d2a8ef27fc8c -eo pid,comm
ERROR: The container started but didn't run the expected command. Please double check your ENTRYPOINT does execute the command passed as docker run argument, as required by official docker images (see https://github.com/docker-library/official-images#consistency for entrypoint consistency requirements).
Alternatively you can force image entrypoint to be disabled by adding option `--entrypoint=''`.
[Pipeline] {
[Pipeline] sh
+ idf.py build
/var/lib/jenkins/workspace/iot-project-TEST@tmp/durable-b8bf6ce0/script.sh: 1: /var/lib/jenkins/workspace/iot-project-TEST@tmp/durable-b8bf6ce0/script.sh: idf.py: not found
[Pipeline] }
$ docker stop --time=1 81920a1146eabe9bf5c08339a682d81ac23777de0421895e1184d2a8ef27fc8c
$ docker rm -f 81920a1146eabe9bf5c08339a682d81ac23777de0421895e1184d2a8ef27fc8c
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

**UPDATE 1:**当我直接执行命令时,使用正式espressif影像的项目建置可以运作,例如:

pipeline {
    agent any

    environment {
        PROJ_NAME = 'test'
    }
    stages {
        stage('Checkout') {
            steps {
                git url: 'ssh://git@bitbucket.org/john/iot-project.git'
            }
        }
        stage('Build') {
            steps{
                sh 'docker run --rm -v $WORKSPACE/ESPComm:/project -w /project espressif/idf:v4.2.2 idf.py build'
            }
        }
    }
}

**UPDATE 2:**如果没有--entrypoint=''参数,则总是会抛出错误,因此我保留了该参数。我将在运行docker后提供lspwd命令的日志。注意:cattop是jenkins自己的技巧,以便执行step块中的命令

第一个

**UPDATE 3:**现在运行时没有入口点命令。请检查日志中的错误:

第一个
我创建了一个映像,它使用ubuntu作为基础,但是没有入口点。我已经成功地实现了eclipse headless-build,如下所示:

stage('Build') {
    agent {
        docker {
            image 'tool/stm32-cubeide-image:1.0'
            reuseNode true
        }
    }
    steps {
        sh '/opt/stm32cubeide/headless-build.sh -importAll $WORKSPACE -data $WORKSPACE -cleanBuild  $DIR/$OPT_BUILD'
    }
}
jaxagkaj

jaxagkaj1#

在执行build命令之前,尝试获取/opt/esp/idf/export.sh,它将设置环境,以便您可以执行build命令。

sh'''
source /opt/esp/idf/export.sh
idf.py build
'''

这是您的完整管道与必要的变化。

pipeline {
    agent any

    environment {
        PROJ_NAME = 'test'
    }
    stages {
        stage('Checkout') {
            steps {
                git url: 'ssh://git@bitbucket.org/john/iot-project.git'
            }
        }
        stage('Build') {
            agent {
                docker {
                    image 'espressif/idf:v4.2.2'
                    args '--rm -v $PWD:/project -w /project'
                    reuseNode true
                }
            }
            steps{
                sh '''
                    #source /opt/esp/idf/export.sh
                    . $IDF_PATH/export.sh
                    idf.py build
                '''
            }
        }
    }
}

更新

下面是入口点中的内容。


# !/usr/bin/env bash

set -e

. $IDF_PATH/export.sh

exec "$@"

因此,按照以下方式执行构建似乎对我很有效。

sh'''
. $IDF_PATH/export.sh
idf.py build
'''

sh'''
sh /opt/esp/entrypoint.sh idf.py build
'''

相关问题