【问题标题】:Not Able to run python command inside jenkins pipeline script无法在詹金斯管道脚本中运行 python 命令
【发布时间】:2021-09-11 19:11:53
【问题描述】:

我正在使用以下命令在 docker 容器中使用 Jenkins

搬运工拉詹金斯/詹金斯

docker run -p 8080:8080 --name=jenkins-master jenkins/jenkins

收到此错误

  • calc.py/var/jenkins_home/workspace/python 计算器@tmp/durable-b7e99e01/script.sh:1:/var/jenkins_home/workspace/python 计算器@tmp/durable-b7e99e01/script.sh:计算。 py: 未找到

存储库链接--https://github.com/jatin633/Calculator.git

  pipeline {
  agent any 
  stages {
    stage('Build') { 
        steps {
            echo 'Building the application....'
            
        }
    }
    stage('Test') { 
        steps {
            echo 'Testing the application....'
            git branch: 'python', url: 'https://github.com/jatin633/Calculator.git'
            sh 'python calc.py'
            sh 'python calculator_unittest.py'
        }
    }
    stage('Deploy') { 
        steps {
            echo 'Deploy the application....'
        }
    }
}

}

【问题讨论】:

  • 如果您签出 Calculator-repository,通常应将其放入单独的文件夹中。我的猜测是您必须将 cd 放入该文件夹。你可以试试吗?
  • 为什么没有 cd 就不行
  • 让我们说这两个文件 calc.py 和calculator_unittest.py 存在于一个 cl 文件夹中,这个命令应该是什么?
  • 检查calc.py的正确可执行权限
  • calc.py 在公共仓库中。它不需要任何证书或权限

标签: jenkins github jenkins-pipeline


【解决方案1】:

我认为 calc.py 文件不在根目录下,所以不妨尝试更改:

stage('Test') { 
    steps {
        echo 'Testing the application....'
        git branch: 'python', url: 'https://github.com/jatin633/Calculator.git'
        sh 'python calc.py'
        sh 'python calculator_unittest.py'
    }
}

进入:

stage('Checkout') { 
    steps {
        echo 'Testing the application....'
        git branch: 'python', url: 'https://github.com/jatin633/Calculator.git'
    }
}
stage('Run Program') {
    dir('sources') {
       steps {
           sh 'python calc.py'
           sh 'python calculator_unittest.py'
       }
    }
}

如果有帮助,请告诉我。问候!

【讨论】:

  • 我已经更改了我的目录并构建了 jenkins Insider docker 现在我没有收到此错误
  • 感谢您的回复
  • 太棒了! @Raghav您能否将我的答案标记为已接受?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多