Files
jenkinsfiles/Jenkinsfile.rip-cd
2025-10-12 16:48:52 -07:00

80 lines
3.3 KiB
Plaintext

pipeline {
agent any
// Define parameters
parameters {
string(name: 'host_ip', description: 'Target System Address')
choice(name: 'cifs_choice', choices: ['TERRA_BEHEMOTH_SMB'], description: 'Choose stored server credentials here')
booleanParam(name: 'eject_drive', defaultValue: false, description: 'Check this option to eject disk at appropriate times')
booleanParam(name: 'remove_local_cache', defaultValue: true, description: 'Check this option to remove local cache data')
string(name: 'disk_drive', defaultValue: '/dev/sr0', description: 'Local DVD Drive device path')
string(name: 'extra_verbose', defaultValue: 'EXTRAVERBOSE=0', description: 'Verbosity Level; 0 by default. Change to 2 for big output')
string(name: 'nogap_enable', defaultValue: 'NOGAP=y', description: 'LAME No-Gap encoding; enabled by default')
string(name: 'server_path', defaultValue: '//172.25.1.10/behemoth/mp3_rip', description: 'Remote Server Path')
}
environment {
ANSIBLE_FORCE_COLOR = '1'
CIFS_CREDENTIALS = credentials("${params.cifs_choice}")
}
options {
ansiColor('xterm')
}
stages {
stage('Generate Inventory File') {
steps {
// Generate the dynamic inventory file
sh """
jenkins_group=\$(echo ${env.BUILD_USER_GROUPS} | sed 's/,/\\n/g' | grep Jenkins | head -n 1)
jenkins_user=\$(echo ${env.BUILD_USER})
cd /var/jenkins_home/ansible
chmod +x /var/jenkins_home/ansible/inventory/inventory.sh
/var/jenkins_home/ansible/inventory/inventory.sh -s -g \$jenkins_group -u \$jenkins_user -i ${params.host_ip}
"""
}
}
stage('Ansible Playbook') {
steps {
//Run the cosmos-base ansible playbook
// /workspace/ansible/playbooks/cosmos-base.yaml
sh """
echo ${params.host_ip}
hash=\$(echo -n ${params.host_ip} | md5sum | cut -c 1-8)
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
cd /var/jenkins_home/ansible
ansible-playbook -i \$inventory_file \
/var/jenkins_home/ansible/playbooks/rip-cd.yaml --ssh-common-args='-o StrictHostKeyChecking=no' \
--extra-vars "CIFS_USERNAME=${env.CIFS_CREDENTIALS_USR} CIFS_PASSWORD=${env.CIFS_CREDENTIALS_PSW} \
CIFS_CREDENTIALS=${env.CIFS_CREDENTIALS} CIFS_CHOICE=${params.cifs_choice} \
disk_drive=${params.disk_drive} extra_verbose=${params.extra_verbose} \
nogap_enable=${params.nogap_enable} server_path=${params.server_path} \
eject_drive=${params.eject_drive} remove_local_cache=${params.remove_local_cache}"
"""
}
}
}
post {
always {
// Remove dynamic Inventory file
sh """
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
rm \$inventory_file
"""
}
}
}