Coder Social home page Coder Social logo

azulinho-jenkins-reconfigure-jobs-using-jinja2's Introduction

This repo contains ansible code to configure jobs in Jenkins using Jinja2 templating

When cloning from github, simply run:

rake

When using galaxy, simply run:

ansible-galaxy install Azulinho.azulinho-jenkins-reconfigure-jobs-using-jinja2

To consume this role, place the following variables into group_vars/all or into a wrapper_role <wrapper_role/vars/main.yaml>

VARIABLES:

azulinho_jenkins_reconfigure_jobs_using_jinja2:
  jobs:
    jinja2_base_template:
      options: &base_template_options { disabled: false,
                                        concurrentbuild: false }

      buildWrappers: &base_template_wrappers
        - &BuildTimeOutWrapper_defaults { type: 'BuildTimeoutWrapper',
                                         timeoutMinutes: 60,
                                         strategy: 'AbsoluteTimeOutStrategy',
                                         failBuild: true,
                                         writingDescription: false }

        - &TimeStamper_defaults { type: 'Timestamper',
                                 options: none }

        - &AnsiColor_defaults { type: 'AnsiColor',
                               colorMapName: xterm }

    jinja2_run_ansible: &jinja2_run_ansible
      description: "Executes Ansible"
      options: { disabled: false,
                 blocks: [ 'downstream', 'upstream' ],
                 concurrentbuild: true }
      parameters: &jinja2_run_ansible_parameters
        - &inventory_file { name: 'INVENTORY_FILE',
            type: 'choice',
            description: 'Which Inventory File to use',
            choices: { type_string: ['vagrant', 'dev', 'qa', 'prd']}}

        - &playbook { name: 'PLAYBOOK',
            type: 'choice',
            description: 'Which playbook to execute',
            choices: { type_string: ['jenkins.yml', 'zabbix.yml', 'site.yml']}}

        - &limit { name: "LIMIT",
            type: 'string',
            description: "Ansible --limit",
            default: "all" }

        - &tags { name: "TAGS",
            type: 'string',
            description: "Ansible --tags",
            default: "" }

        - &start_at_task { name: "START_AT_TASK",
            type: 'string',
            description: "Ansible --start-at-task",
            default: "" }

        - &release { name: "RELEASE",
            type: 'string',
            description: "RELEASE number to use",
            default: "latest" }

        - &vault { name: "VAULT",
            type: 'password',
            description: "Ansible Vault Password",
            default: "" }

      scm:
        - { type: 'git',
            url: 'https://github.com/Azulinho/ansible-jenkins-showcase.git',
            branches: ['*/master'] }

      builders:
        - { type: 'shell',
            command_lines: [
              "#!/bin/bash",
              "export PATH=/usr/local/bin:$PATH",
              "export PYTHONUNBUFFERED=1",
              "echo $VAULT &gt; .vault",
              "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u vagrant -s -i $INVENTORY_FILE -l $LIMIT $PLAYBOOK --vault-password-file .vault" ]}

      buildWrappers: *base_template_wrappers

    jinja2_deploy_zabbix:
      <<: *jinja2_run_ansible
      parameters: [
        <<: *limit,
        <<: *tags,
        <<: *start_at_task,
        <<: *release,
        <<: *vault,
        { name: 'PLAYBOOK',
            type: 'string',
            description: 'Which playbook to execute',
            default: 'zabbix.yml'},
        { name: 'INVENTORY_FILE',
            type: 'string',
            description: 'Which Inventory File to use',
            default: 'vagrant'} ]
      publishers:
        - { type: 'parametrizedTrigger',
            projects: ['jinja2_deploy_zabbix_checks'],
            parameters: ['<hudson.plugins.parameterizedtrigger.CurrentBuildParameters/>'],
            condition: 'success'}

    jinja2_deploy_zabbix_checks:
      <<: *jinja2_run_ansible
      parameters: [
        <<: *limit,
        <<: *tags,
        <<: *start_at_task,
        <<: *release,
        <<: *vault,
        { name: 'PLAYBOOK',
            type: 'string',
            description: 'Which playbook to execute',
            default: 'zabbix-checks.yml'},
        { name: 'INVENTORY_FILE',
            type: 'string',
            description: 'Which Inventory File to use',
            default: 'vagrant'} ]
      publishers:
        - { type: 'parametrizedTrigger',
            projects: ['jinja2_run_zabbix_tests'],
            parameters: ['<hudson.plugins.parameterizedtrigger.CurrentBuildParameters/>'],
            condition: 'success'}

    jinja2_run_zabbix_tests:
      <<: *jinja2_run_ansible
      builders:
        - { type: 'shell',
            command_lines: [
              "#!/bin/bash",
              "echo SUCESS" ]}
      options: *base_template_options
      buildWrappers: *base_template_wrappers

    jinja2_deploy_template:
      options: &deploy_template_options { disabled: false,
                                          blocks: [ 'downstream',
                                                    'upstream' ],
                                          concurrentbuild: true }
      builders:
        - { type: 'shell',
            command_lines: [
              "#!/bin/bash",
              "echo $VAULT &gt; .vault",
              "ansible-playbook -s -i $INVENTORY_FILE -l $LIMIT $PLAYBOOK --vault-password-file .vault" ]}

    jinja2_example1:
      options: *deploy_template_options
      parameters:
        - { name: "PARAMETER1",
            type: 'string',
            description: "PARAMETER 1",
            default: "all" }
      builders:
        - { type: 'shell',
            command_lines: [
              "#!/bin/bash",
              "echo deploy_job1" ]}
      buildWrappers: *base_template_wrappers
      publishers:
        - { type: 'parametrizedTrigger', projects: ['deploy_job2'], condition: 'success', parameters: ['VAR1=var1', 'VAR2=var2'], triggerWithNoParameters: false }

    jinja2_example2:
      options: *deploy_template_options
      builders:
        - { type: 'shell',
            command_lines: [
              "#!/bin/bash",
              "echo deploy_job2" ]}
      buildWrappers: [ *BuildTimeOutWrapper_defaults, *TimeStamper_defaults, *AnsiColor_defaults ]
      publishers:
        - { type: 'parametrizedTrigger', projects: ['deploy_job3'], condition: 'success', parameters: ['VAR1=var1', 'VAR2=var2'], triggerWithNoParameters: false }

    jinja2_example3: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job3" ]} ], buildWrappers: *base_template_wrappers , publishers: [ {type: 'parametrizedTrigger', projects: ['deploy_job4']} ] }
    jinja2_example4: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job4" ]} ], buildWrappers: *base_template_wrappers , publishers: [ {type: 'parametrizedTrigger', projects: ['deploy_job5']} ]}
    jinja2_example5: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job5" ]} ], buildWrappers: *base_template_wrappers , publishers: [ {type: 'parametrizedTrigger', projects: ['deploy_job6']} ]}
    jinja2_example6: { options: *deploy_template_options, builders: [ { type: 'shell', command_lines: [ "#!/bin/bash", "echo deploy_job6" ]} ], buildWrappers: *base_template_wrappers }

azulinho-jenkins-reconfigure-jobs-using-jinja2's People

Contributors

azulinho avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.