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

+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env groovy
// Deploy a Deployment to k3s.
// Usage: deployToK3s(name: 'demo', image: 'nginx', replicas: 2)
def call(Map config = [:]) {
def name = config.name ?: error('deployToK3s: "name" is required')
def image = config.image ?: error('deployToK3s: "image" is required')
def replicas = config.replicas ?: 1
def namespace = config.namespace ?: 'default'
stage("Deploy ${name}") {
writeFile file: 'deploy.yaml', text: """
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${name}
namespace: ${namespace}
spec:
replicas: ${replicas}
selector:
matchLabels:
app: ${name}
template:
metadata:
labels:
app: ${name}
spec:
containers:
- name: ${name}
image: ${image}
"""
sh 'kubectl apply -f deploy.yaml'
sh "kubectl rollout status deployment/${name} -n ${namespace} --timeout=90s"
}
}
+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}"
"""
}
}
}
}