Jenkins Integrated pipeline,ansible Process

Source: Internet
Author: User

1. Configuring the Jenkins Environment

Command refer to the previous article "Docker Build Jenkin". Single-Machine deployment. In this example. Jenkins,ansible installed on the same machine.

Jenkins needs to configure/etc/sudoers. Also need to give/bin/bash, as well as Jenkins's home directory under. SSH requires a copy of the ansible SSH private key

1. Configure/etc/sudoers

Root    all=(All)       all# add jenkins  all = (All) nopasswd:all

2.VIM/ETC/PASSWD Change Jenkin to bash permissions, note home directory. I'm going to test the RSA private key.

JENKINS:X:996:993: Jenkins Automation Server:/var/lib/jenkins:/bin/bash

3. Copy a private key to Jenkins call Ansible

Ssh-keygen-t RSACP ~/.ssh/id_rsa/var/lib/jenkins/.ssh/res.jenkins

  

2. Configure Pipeline

Create a new pipeline pipeline project (seemingly only pipeline can insert pipeline script)

The script requires strict reference to the pipeline syntax.

Pipeline {Agent any stages {stage ('Start Deployment Notifications'{steps {script {hostname=hostname #前一个为定义变量住后面build Job, and the latter defines the input variable region for the graphical interface above='SDASDF'+Region #字符拼接有严格要求. The string used for stitching cannot have special characters such as spaces or/n line breaks. Otherwise pipeline syntax cannot be unrecognized} sh'echo "Note: Before you proceed, check to see if the target server that is about to be published is matched by Job-get-hosts-info. "'Timeout (time:Ten, Unit:'MINUTES') {input (message:'The information is correct, continue the subsequent release operation?') #这三行可以忽略 Build job:'Ansible-alter', Parameters: [String (Name:'hostname', Value:hostname), String (name:' Region', Value:region)] }            }        }    }}

Create a free-style project. Used to invoke Ansible

Build Step Select Execute Shell

#!/bin/bash#echo" Note: The host name you are working on is: ${hostname}, the host area is: Regin = ${region}" "Title=${hostname } content=${region}"./post_message.yml--private-key=/  var/lib/jenkins/. ssh/res.jenkins
#此处可以改成自己想要的命令行. Not necessarily ansible. It can also be a salt script and so on.

3. Configure Ansible

Here is a POST request sent by a ansible. Sent to a mail service interface.

-name:send Mail Gather_facts:false hosts:"localhost"user:root vars:start_time:'{{lookup ("pipe", "Date +%s")}}'task_id:'{{lookup ("pipe", "echo" + groups.newprosfs|string + "|md5sum")}}'tasks:-name:send Mail uri:url:http://115.159.112.97:2020Method:post Body: {"title":"{{title}}","content":"{content}}","Mail_receiver":"[Email protected]com"," the":"Mail","Mail_type":"HTML"} status_code: $Body_format:json

Jenkins integrated pipeline,ansible process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.