尝试使用curl将Jenkins工作区中的pdf文件上传到nexus

问题描述 投票:0回答:1

我正在 Jenkins 管道构建后操作中使用 checkmarx 运行 DAST 扫描,扫描结果采用 Jenkins 工作区 pdf 格式,我将工作区保存为变量并将 *.pdf 文件复制到我创建的文件夹中,每次扫描都有一个扫描结果上的日期和时间戳。我只想将我创建的文件夹内的 pdf 文件复制到 Nexus 存储库,但我的curl 命令复制文件夹 nexus 而不是 pdf 文件。

post {
      always {
        // Upload checkmarxs scan result to nexus repository
        script {
def workspace="/var/lib/jenkins/jobs/Sec/checkmarxscan/workspace/Checkmarx/Scan/CxSASTReport_18_05_2024-02_04_29.pdf" 
          def pdfDir = "pdf_files" 
          sh "mkdir -p ${pdfDir}"
          sh "cp ${workspace}*.pdf ${pdfDir}/"
          def loadTXT = ''     
          def buildNumber = env.BUILD_NUMBER
          def nexusUrl = 'https://nexus.com'
          def UploadUrl = "${nexusUrl}/repository/Sec/ScanRelease-${buildNumber}/Scan"
          def file = ${pdfDir}

         // define curl upload 
         withCredentials([usernamePassword(credentialsId: 'nexus-login', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
                            loadTXT = sh(script: "curl -s -u ${USERNAME}:${PASSWORD} --upload-file ${file} ${UploadUrl}/${file}", returnStdout: true)
                     }
        echo "Upload Complete"
      }
     }
   }
jenkins curl nexus
1个回答
0
投票
  1. 附件 1 -
    def file = ${pdfDir}
  2. 附件 2 -
    curl ... --upload-file ${file}

不确定为什么您希望代码上传文件

© www.soinside.com 2019 - 2024. All rights reserved.