Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Jenkins server to build PR and provide feedback #328

Merged
merged 7 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 25 additions & 15 deletions Jenkinsfile
Expand Up @@ -2,13 +2,26 @@ pipeline {
agent any

options {
disableConcurrentBuilds()
skipDefaultCheckout()
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
skipDefaultCheckout()
timeout(time: 1, unit: 'HOURS')
}

parameters {
string(name: 'vsphere_server', defaultValue: '10.1.83.17', description: 'vSphere host')
string(name: 'datastore', defaultValue: 'iSCSI-2', description: 'vSphere datastore')
string(name: 'template', defaultValue: 'jenkins/ecsce-template', description: 'VM template')
string(name: 'resource_pool', defaultValue: 'Cisco UCS Cluster/Resources/Tests', description: 'vSphere resource pool')
string(name: 'datacenter', defaultValue: 'Datacenter', description: 'vSphere datacenter')
string(name: 'network_interface', defaultValue: 'VM Network', description: 'VM network interface')
string(name: 'ecs_nodes', defaultValue: '1', description: 'Number of ECS nodes to be deployed')
}

environment {
TF_VAR_vsphere_user = "${params.vsphere_user}"
TF_VAR_vsphere_password = "${params.vsphere_password}"
VSPHERE = credentials('vsphere_gotham')
SSH = credentials('ssh_credentials')
TF_VAR_vsphere_user = "${VSPHERE_USR}"
TF_VAR_vsphere_password = "${VSPHERE_PSW}"
TF_VAR_vsphere_server = "${params.vsphere_server}"
TF_VAR_datastore = "${params.datastore}"
TF_VAR_template = "${params.template}"
Expand All @@ -22,13 +35,10 @@ pipeline {
stages {
stage('Checkout') {
steps {
git url: 'https://github.com/EMCECS/ECS-CommunityEdition', branch: "${params.branch}"
checkout scm
sh 'printenv'
script {
// Workaround until the GIT plugin automatically injects these environment variables
env.BRANCH_NAME = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
env.COMMIT_ID = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
env.AUTHOR_NAME = sh(returnStdout: true, script: 'git show -s --pretty=%an HEAD').trim()
env.REPO_URL = sh(returnStdout: true, script: 'git remote get-url origin').trim()
}
}
}
Expand Down Expand Up @@ -56,9 +66,9 @@ pipeline {
playbook: 'tests/ansible/install_node.yml',
inventory: 'hosts.ini',
extraVars: [
ansible_ssh_user: "${params.ssh_user}",
ansible_ssh_pass: "${params.ssh_pass}",
ansible_become_pass: "${params.ssh_pass}",
ansible_ssh_user: "$SSH_USR",
ansible_ssh_pass: "$SSH_PSW",
ansible_become_pass: "$SSH_PSW",
current_directory: "$WORKSPACE"
],
extras: '-vvv'
Expand All @@ -72,10 +82,10 @@ pipeline {
sh 'terraform destroy -force tests'
}
success {
slackSend channel: 'ecs-community-edition', color: 'good', message: "Build <${env.BUILD_URL}|#${env.BUILD_NUMBER}> passed: ${env.JOB_NAME}@${env.BRANCH_NAME} (<${env.REPO_URL}|${env.COMMIT_ID}>) by ${env.AUTHOR_NAME}"
slackSend channel: 'ecs-community-edition', color: 'good', message: "Build <${env.BUILD_URL}|#${env.BUILD_NUMBER}> passed: ${env.JOB_NAME}@${env.CHANGE_BRANCH} (<${env.CHANGE_URL}|${env.COMMIT_ID}>) by ${env.CHANGE_AUTHOR_DISPLAY_NAME}"
}
failure {
slackSend channel: 'ecs-community-edition', color: 'danger', message: "Build <${env.BUILD_URL}|#${env.BUILD_NUMBER}> failed: ${env.JOB_NAME}@${env.BRANCH_NAME} (<${env.REPO_URL}|${env.COMMIT_ID}>) by ${env.AUTHOR_NAME}"
slackSend channel: 'ecs-community-edition', color: 'danger', message: "Build <${env.BUILD_URL}|#${env.BUILD_NUMBER}> failed: ${env.JOB_NAME}@${env.CHANGE_BRANCH} (<${env.CHANGE_URL}|${env.COMMIT_ID}>) by ${env.CHANGE_AUTHOR_DISPLAY_NAME}"
}
}

Expand Down
37 changes: 15 additions & 22 deletions tests/ansible/roles/install_node/tasks/main.yml
@@ -1,40 +1,37 @@
- name: Set authorized key
authorized_key:
user: centos
user: root
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"

- name: Install packages
become: true
- name: Install rsync package
package:
name: "{{ item }}"
name: rsync
state: latest
with_items:
- git
- rsync

- name: Copy files to installer node
synchronize:
src: "{{ current_directory }}/"
dest: /home/centos/ecs
dest: /root/ecs
recursive: yes

- name: Remove rsync package
package:
name: rsync
state: absent

- name: Provide the deploy.yml file
template:
src: deploy.yml.j2
dest: /home/centos/ecs/deploy.yml
owner: centos
group: centos
dest: /root/ecs/deploy.yml
owner: root
group: root

- name: Run boostrap script
shell: /home/centos/ecs/bootstrap.sh -n -b http://10.1.83.5/alpine -g -k /home/centos/ecs/contrib/sslproxycert/emc_ssl.pem -p 10.1.83.5:3128 -c /home/centos/ecs/deploy.yml
become: true
become_method: sudo
shell: /root/ecs/bootstrap.sh -n -b http://10.1.83.5/alpine -g -k /root/ecs/contrib/sslproxycert/emc_ssl.pem -p 10.1.83.5:3128 -c /root/ecs/deploy.yml

- name: reboot nodes
shell: sleep 2 && shutdown -r now "Ansible reboot"
become: true
become_method: sudo
async: 1
poll: 0
ignore_errors: true
Expand All @@ -43,11 +40,7 @@
local_action: wait_for host="{{ inventory_hostname }}" port=22 state=started delay=30 timeout=300

- name: Run Step1
shell: /root/bin/step1
become: true
become_method: sudo
shell: step1

- name: Run Step2
shell: /root/bin/step2
become: true
become_method: sudo
shell: step2