首页 > 解决方案 > 在 jenkins 管道阶段签出后如何使用 git 存储库

问题描述

我正在尝试在我的 jenkins piepline 的一个阶段中提取第二个 github 存储库。我想在下一阶段使用提取的 repo 运行一个名为 test.py 的测试用例。运行“测试”阶段时,我收到错误消息,因为找不到文件。

stage('Checking out first') {
          steps {
            dir('sources') {
                git(url: 'https://github.com/second-repo.git', branch: 'master')
            }
          }
        }

stage('Test') {
            agent {
                docker {
                    image 'qnib/pytest'
                }
            }
            steps {
                sh 'py.test --junit-xml test-reports/results.xml sources/test.py'
            }
            post {
                always {
                    junit 'test-reports/results.xml'
                }
            }
        }
Error: 
+ py.test --junit-xml test-reports/results.xml sources/test.py

============================= test session starts ==============================

platform linux2 -- Python 2.7.14, pytest-3.5.0, py-1.5.3, pluggy-0.6.0

rootdir: /var/jenkins_home/workspace/second-repo, inifile:

plugins: cov-2.5.1



 generated xml file: /var/jenkins_home/workspace/second-repo/test-reports/results.xml 

========================= no tests ran in 0.00 seconds =========================

ERROR: file not found: sources/test.py



script returned exit code 4

标签: pythongitjenkinsjenkins-pipeline

解决方案


推荐阅读