i am running a DAST scan using checkmarx in Jenkins pipeline post build action, the scan result is in the Jenkins workspace pdf format, i saved the workspace as a variable and copied *.pdf file to a folder i created, each scan has a date and timestamp on the scan result. I want to copy only the pdf file inside the folder i created to Nexus repository, but my curl command copies the folder nexus instead of the pdf file.
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"
}
}
}