Jenkins文件参数

mkh04yzy  于 2023-10-17  发布在  Jenkins
关注(0)|答案(1)|浏览(173)

我创建了一个简单的管道脚本,它传递在我的python脚本上声明的参数。但是,我的脚本中的文件参数似乎没有存储在我的jenkins工作空间中。知道为什么我的文件没有上传吗?有什么建议吗?非常感谢你

流水线脚本:

pipeline
{
    options {
        buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5'))
    }
    
    agent {
        label "ubuntu-python"
    }
    parameters {
        file(
            name: 'USERS_XML',
            description: 'parse user.xml'
        )
    }
        // Global shell environment
    environment {
        HOME="${WORKSPACE}"
    }
    stages{
        stage('Checkout'){
            steps{
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'git', url: 'https://bitbucket.com/bitbucket/scm/~user/samplecode.git']]])
            }
        }
        stage('Python modules'){
            steps{
                sh """
                python3 --version
                pip3 --version
               
                #Install required modules
                pip3 install requests
                pip3 install TestLink-API-Python-client
                pip3 install openpyxl
                """
            }
        }
        stage('Get Testlink Users'){
            steps{
                sh label: 'Display testlink users', 
                script: '''
                
                python3 -u testlink.py "${USERS_XML}"
                    
                '''
            }
        }
    }
    post{
        success {
            archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.xlsx', caseSensitive: false, onlyIfSuccessful: true
        }
    }
}

错误信息:

+ python3 -u testlink.py   tl-server devKey users.xml
------- User List for tl-server -------
Traceback (most recent call last):
  File "testlink.py", line 120, in <module>
    serverList()
  File "testlink.py", line 28, in serverList
    tree = ET.parse(""+USERS_XML+"") 
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1202, in parse
    tree.parse(source, parser)
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 584, in parse
    source = open(source, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'users.xml'
taor4pac

taor4pac1#

我认为旧的文件参数有一些问题,一般我使用file paramter plugin

parameters {
  stashedFile description: 'test', name: 'users.xml'
}
 // ....
stages {
  stage('Test') {
    steps {
      unstash 'users.xml'
      sh 'cat users.xml'
    }
  }
}

相关问题