-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
58 lines (52 loc) · 1.7 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
pipeline {
agent any
parameters {
choice(
name: 'ACTION',
choices: ['Rebuild Environment', 'Restart Containers', 'Full Redeploy'],
description: 'Select the action to perform'
)
}
environment {
SERVER_IP = '192.168.1.148' // Replace with your server's IP
SSH_USER = 'mateuszg' // Replace with your SSH username
CONFIG_PATH = '/home/mateuszg/IdeaProjects/mati-lab/nixos' // Path to your NixOS configuration
}
stages {
stage('Perform Action') {
steps {
script {
// Execute action based on selected choice
if (params.ACTION == 'Rebuild Environment') {
rebuildEnvironment()
} else if (params.ACTION == 'Restart Containers') {
restartContainers()
} else if (params.ACTION == 'Full Redeploy') {
fullRedeploy()
} else {
error("Unknown action: ${params.ACTION}")
}
}
}
}
}
}
def rebuildEnvironment() {
echo 'Rebuilding NixOS environment...'
sh """
ssh ${env.SSH_USER}@${env.SERVER_IP} \
"sudo nixos-rebuild switch -I nixos-config=${env.CONFIG_PATH}/configuration.nix"
"""
}
def restartContainers() {
echo 'Restarting Docker containers...'
sh """
ssh ${env.SSH_USER}@${env.SERVER_IP} \
"cd ${env.CONFIG_PATH}/docker && docker-compose down && docker-compose up -d"
"""
}
def fullRedeploy() {
echo 'Performing full redeploy...'
rebuildEnvironment()
restartContainers()
}