在Jenkins文件中运行诗歌

2024-06-08 12:15:49 发布

您现在位置:Python中文网/ 问答频道 /正文

安装程序是Jenkins在Kubernetes运行。我想整理代码,运行测试,然后构建一个容器。在我的一个构建步骤中安装/运行诗歌时遇到问题

podTemplate(inheritFrom: 'k8s-slave', containers: [
    containerTemplate(name: 'py38', image: 'python:3.8.4-slim-buster', ttyEnabled: true, command: 'cat')
  ]) 
{
    node(POD_LABEL) {

        stage('Checkout') {
            checkout scm
            sh 'ls -lah'
        }

        container('py38') {
            stage('Poetry Configuration') {
                sh 'apt-get update && apt-get install -y curl'
                sh "curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python"
                sh "$HOME/.poetry/bin/poetry install --no-root"
                sh "$HOME/.poetry/bin/poetry shell --no-interaction"
            }

            stage('Lint') {
                sh 'pre-commit install'
                sh "pre-commit run --all"
            }
        }
    }
}

诗歌安装工作正常,但当我去激活shell时,它失败了

+ /root/.poetry/bin/poetry shell --no-interaction
Spawning shell within /root/.cache/pypoetry/virtualenvs/truveris-version-Zr2qBFRU-py3.8

[error]
(25, 'Inappropriate ioctl for device')

Tags: installnohomegetpoetrybinshapt
2条回答

这里的问题是Jenkins运行一个非交互式shell,而您正试图启动一个交互式shell。 no-interaction选项并不意味着非交互式shell,而是指不向您提问的shell:

  -n ( no-interaction)  Do not ask any interactive question

This answer explains it🔑🔑.

我不会调用shell,而是使用poetry run🏃🏃 命令:

podTemplate(inheritFrom: 'k8s-slave', containers: [
    containerTemplate(name: 'py38', image: 'python:3.8.4-slim-buster', ttyEnabled: true, command: 'cat')
  ]) 
{
    node(POD_LABEL) {

        stage('Checkout') {
            checkout scm
            sh 'ls -lah'
        }

        container('py38') {
            stage('Poetry Configuration') {
                sh 'apt-get update && apt-get install -y curl'
                sh "curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python"
                sh "$HOME/.poetry/bin/poetry install  no-root"
            }

            stage('Lint') {
                sh "$HOME/.poetry/bin/poetry run 'pre-commit install'"
                sh "$HOME/.poetry/bin/poetry run 'pre-commit run  all'"
            }
        }
    }
}

✌️

在容器级别安装poetry,然后使用解析poetry.lock文件

poetry export  without-hashes  dev -f requirements.txt -o requirements.txt

然后用pip install -r requirements.txt而不是poetry install安装依赖项

这样就不必在虚拟环境中运行命令

相关问题 更多 >