Skip to content
Snippets Groups Projects
Commit 6d92344a authored by Bo-Chun Chen's avatar Bo-Chun Chen
Browse files

Init commit

parents
No related branches found
No related tags found
No related merge requests found
pipeline {
agent none
options {
gitlabBuilds(builds: ['Linting', 'Build image'])
}
stages {
stage('Linting') {
agent {
docker {
image 'cytopia/ansible-lint'
args '--entrypoint= '
}
}
steps {
script {
try {
sh 'ansible-lint build.yaml'
} catch (err) {
echo err.getMessage()
unstable('Linting failed')
}
}
}
post {
success {
updateGitlabCommitStatus name: 'Linting', state: 'success'
}
unstable {
updateGitlabCommitStatus name: 'Linting', state: 'failed'
}
}
}
stage('Build image') {
agent {
docker {
image 'gitlab.rc.uab.edu:4567/louistw/utility:v0.1'
args '-u root:root -v /var/jenkins_home/.ssh:/root/.ssh --add-host=ruffner.rc.uab.edu:192.168.16.10'
}
}
environment {
GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse --short $GIT_COMMIT').trim()
APP_CRED = credentials('uab-dev-openrc')
}
steps {
sh '''
echo "hosts: files dns" > /etc/nsswitch.conf
. ${APP_CRED}
floatingip=(`openstack floating ip create -c id -c floating_ip_address -f value bright-external-flat-externalnet`)
read -r FLOATING_IP FLOATING_IP_ID <<< ${floatingip[@]}
packer build --var "build_version=$GIT_COMMIT" \
--var "ssh_host=$FLOATING_IP" \
--var "floating_ip=$FLOATING_IP_ID" \
test-build.json
openstack floating ip delete $FLOATING_IP_ID
'''
}
post {
success {
updateGitlabCommitStatus name: 'Build image', state: 'success'
echo 'build ood image success'
}
failure {
updateGitlabCommitStatus name: 'Build image', state: 'failed'
echo 'build ood image failed'
}
}
}
}
}
---
- hosts: localhost
tasks:
- name: Install pip
yum:
name:
- yum-utils
- python-pip
- vim
- name: Create file at /root
copy:
content: "build completed"
dest: "/root/build-result"
- name: Verify build
debug:
msg: "{{ lookup('file', '/root/build-result') }}"
{
"builders":[
{
"type": "openstack",
"image_name": "testbuild-{{user `build_version`}}",
"source_image_name": "CentOS-7-x86_64-GenericCloud-1905",
"flavor": "m1.medium",
"floating_ip": "{{ user `floating_ip` }}",
"networks": [ "913c4b31-f101-4cfc-8648-28e214ddee16" ],
"instance_floating_ip_net": "913c4b31-f101-4cfc-8648-28e214ddee16",
"ssh_host": "{{ user `ssh_host` }}",
"ssh_username": "centos",
"ssh_keypair_name": "jenkins-keypair",
"ssh_private_key_file": "/root/.ssh/id_rsa",
"reuse_ips": true
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"sudo yum install -y epel-release",
"sudo yum install -y ansible git vim bash-completion",
"sudo yum install -y NetworkManager",
"sudo systemctl restart NetworkManager",
"sudo nmcli con mod 'Wired connection 1' connection.id 'eth1'"
]
},
{
"type": "ansible-local",
"playbook_file": "./build.yaml",
"extra_arguments": [ "-b" ]
}
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment