Upload files to "vars"

This commit is contained in:
khaled committed 2026-09-30 14:34:09 +00:00
1 parent 356faba67a
commit 9c022dd78f
2 files changed
+59

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env groovy
// Upload a file to Artifactory. Shows the HTTP code and fails on >= 400.
// Usage: publishArtifact(file: 'app.tar.gz', path: 'demo/1.0.0')
def call(Map config = [:]) {
def file = config.file ?: error('publishArtifact: "file" is required')
def path = config.path ?: error('publishArtifact: "path" is required')
def repo = config.repo ?: 'lab-generic-local'
def base = config.base ?: 'http://10.0.1.4:8082/artifactory'
container('build') {
stage('Publish to Artifactory') {
withCredentials([string(credentialsId: 'artifactory-token', variable: 'ART_TOKEN')]) {
sh """
HTTP=\$(curl -s -o /tmp/resp.txt -w '%{http_code}' \
-H "Authorization: Bearer \${ART_TOKEN}" \
-T ${file} \
${base}/${repo}/${path}/${file})
echo "Artifactory responded HTTP \${HTTP}"
cat /tmp/resp.txt
[ "\${HTTP}" -lt 400 ] || exit 1
echo ""
echo "Published: ${base}/${repo}/${path}/${file}"
"""
}
}
}
}