Files
homepage/Jenkinsfile
T

46 lines
1.2 KiB
Groovy
Raw Normal View History

2024-12-22 20:10:40 +01:00
pipeline {
2024-12-23 12:34:23 +01:00
agent any
2024-12-22 20:21:22 +01:00
2024-12-22 20:13:05 +01:00
environment {
2025-01-17 22:32:18 +01:00
REGISTRY = "docker.internal.jason-e.dev:8443"
2024-12-22 20:13:05 +01:00
IMAGE_NAME = "efstajas/homepage"
}
2024-12-22 20:10:40 +01:00
stages {
2024-12-22 20:13:05 +01:00
stage('Docker Build') {
steps {
script {
2024-12-23 12:49:18 +01:00
dockerImage = docker.build("$IMAGE_NAME")
2024-12-22 20:13:05 +01:00
}
}
2024-12-22 20:06:11 +01:00
}
2024-12-22 20:13:05 +01:00
stage('Docker Publish') {
steps {
script {
2025-01-17 22:32:18 +01:00
docker.withRegistry("https://$REGISTRY") {
2024-12-22 20:13:05 +01:00
dockerImage.push("latest")
}
}
2024-12-22 20:10:40 +01:00
}
}
2024-12-23 15:01:47 +01:00
2024-12-23 15:29:13 +01:00
stage('Deploy to Nomad') {
2024-12-23 15:01:47 +01:00
steps {
script {
2024-12-26 12:51:24 +01:00
// Calculate the hash of your Docker image (or your application code)
2024-12-26 12:53:23 +01:00
def imageHash = sh(script: "docker images --no-trunc $IMAGE_NAME | grep latest | awk '{print \$3}'", returnStdout: true).trim()
2024-12-26 12:51:24 +01:00
// Read the jobspec.json file
def jobSpec = readJSON file: 'jobspec.json'
// Write the updated jobspec back to the file
def updatedJobSpec = sh(script: "jq '.meta[\"image_hash\"] = \"$imageHash\"' jobspec.json", returnStdout: true).trim()
sh 'curl -X POST -H "Content-Type: application/json" -d "$updatedJobSpec" http://nomad.service.consul:4646/v1/jobs'
2024-12-23 15:01:47 +01:00
}
}
}
}
2024-12-22 19:58:51 +01:00
}