无法在 jenkins 管道脚本中运行 python 命令

时间:2021-06-29 14:44:50

标签: jenkins github jenkins-pipeline

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

docker pull jenkins/jenkins

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

出现这个错误

  • calc.py/var/jenkins_home/workspace/pythoncalculator@tmp/durable-b7e99e01/script.sh:1:/var/jenkins_home/workspace/pythoncalculator@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....'
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

我认为 calc.py 文件不在 root 中,所以也许尝试更改:

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'
       }
    }
}

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