官术网_书友最值得收藏!

Setting up Jenkins

Let's use an Ansible playbook to install Jenkins and get started with it. 

The following code snippet is a snippet of an Ansible playbook we wrote for setting up Jenkins in the Ubuntu 16.04 OS.

Once the setup has been done, playbook returns the default administrator password required to log in to the application for the first time:

- name: installing jenkins in ubuntu 16.04
hosts: "192.168.1.7"
remote_user: ubuntu
gather_facts: False
become: True

tasks:
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)

- name: install curl and git
apt: name={{ item }} state=present update_cache=yes

with_items:
- curl
- git

  - name: adding jenkins gpg key
    apt_key:
      url: https://pkg.jenkins.io/debian/jenkins-ci.org.key
      state: present

  - name: jeknins repository to system
    apt_repository:
      repo: http://pkg.jenkins.io/debian-stable binary/
      state: present

  - name: installing jenkins
    apt:
      name: jenkins
      state: present
      update_cache: yes

- name: adding jenkins to startup service: name: jenkins state: started enabled: yes - name: printing jenkins default administration password command: cat /var/lib/jenkins/secrets/initialAdminPassword register: jenkins_default_admin_password - debug: msg: "{{ jenkins_default_admin_password.stdout }}"

To set up Jenkins, run the following command. Where 192.168.1.7 is the server IP address where Jenkins will be installed:

ansible-playbook -i '192.168.1.7,' site.yml --ask-sudo-pass

Now we can configure Jenkins to install plugins, run scheduled jobs, and do many other things. First, we have to navigate to the Jenkins dashboard by browsing to http://192.168.1.7:8080 and providing the auto-generated password. If the playbook runs without any errors, it will display the password at the end of the play:

Create the new user by filling in the details and confirming to log in to the Jenkins console:

Now we can install custom plugins in Jenkins, navigate to the Manage Jenkins tab, select Manage Plugins, then navigate to the Available tab. In the Filter: enter the plugin name as Ansible. Then select the checkbox and click Install without restart:

Now we are ready to work with the Ansible plugin for Jenkins. Create a new project in the main dashboard, give it a name, and select Freestyle project to proceed:

Now we can configure the build options, this is where Jenkins will give us more flexibility to define our own triggers, build instructions, and post build scripts:

The preceding screenshot is an example of a build invoking an Ansible ad-hoc command. This can be modified to ansible-playbook or any other scripts based on certain events.

The Jenkins Ansible plugin also provides useful features such as configuring advanced commands and passing credentials, keys from Jenkins itself.

Once the build triggers based on an event, this can be sent to some artifact storage, it can also be available in the Jenkins build console output:

This is a really very powerful way to perform dynamic operations such as triggering automated server and stacks setup based on a code push to the repository, as well as scheduled scans and automated reporting.

主站蜘蛛池模板: 泌阳县| 正安县| 永福县| 本溪市| 寿宁县| 平顶山市| 甘德县| 通辽市| 泗洪县| 长葛市| 临泽县| 乡宁县| 图们市| 吉水县| 罗定市| 马公市| 大庆市| 昭苏县| 江孜县| 安乡县| 武平县| 额敏县| 寿宁县| 鸡泽县| 古丈县| 额济纳旗| 彭阳县| 唐河县| 冷水江市| 包头市| 潮州市| 丹东市| 株洲市| 富阳市| 威远县| 安庆市| 巴青县| 鄂托克旗| 马关县| 翼城县| 松溪县|