无法执行“python -m py_compile”命令

时间:2021-05-16 12:04:39

标签: python jenkins jenkins-pipeline

我是 python 新手,我尝试从 git 编译一些开源,并使用 jenkins 管道执行一些 shell 脚本。

我的詹金斯代码:

pipeline
{
    agent any
    stages
    {
        stage("Git-Clone")
        
        {
            steps{
            git 'https://github.com/Vsb19/simple-python-pyinstaller-app.git'
            }
        }
        stage('Shell scripts')
        {
            steps
            {
                sh  'python -m py_compile sources/add2vals.py sources/calc.py'
            }
            
        }
        
    }
}

运行后出现如下问题:

[Pipeline] sh
+ python -m py_compile sources/add2vals.py sources/calc.py
/var/lib/jenkins/workspace/sample-python@tmp/durable-b12d65e6/script.sh: 1: python: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

我在我的 ubuntu 虚拟机中安装了 java、python、pip、Jenkins

1 个答案:

答案 0 :(得分:0)

很可能 python 可执行文件不在 jenkins 用户的 $PATH 中。使用完整路径应该可以解决它,例如:

sh  '/usr/bin/python -m py_compile sources/add2vals.py sources/calc.py'