Skip to content

Instantly share code, notes, and snippets.

View smalltown's full-sized avatar

smalltown

View GitHub Profile
//
// This Groovy snippet is used for Jenkins Job DSL groovy script,
// when ...
// 1. enable Jenkins Global Security
// 2. use pipelineJob
// 3. want to approve pipeline cps automatically
//
import jenkins.model.Jenkins
# clean old properties and script file
rm -rf *
# copy the latest properties and script file
cp -rf /var/lib/jenkins/dsl-repo/config ./
cp -rf /var/lib/jenkins/dsl-repo/dsl ./
cp -rf /var/lib/jenkins/dsl-repo/pipeline ./
# reload pipeline global library
rm -rf /tmp/workflowLibs
import groovy.json.*
def deploy(phase, version, user, branch, status = 'Success', region = 'Oregon', channel = 'none', repoer = 'true', repo_host, repo_owner) {
def slack_info = slack_info.load()
def http_client = new com.droi.pipeline.jenkins.httpRequest(slack_info.hook_protocol, slack_info.hook_fqdn, slack_info.hook_port.toInteger())
def header = ["Content-Type": "application/json"]
def url = "${slack_info.hook_protocol}://${slack_info.hook_fqdn}/${slack_info.hook_uri}"
def response = [:]
@smalltown
smalltown / Jenkins_Job_DSL_GitLab_Trigger
Created October 21, 2017 01:29
Jenkins job DSL for integrating GitLab
import jenkins.model.Jenkins
// define global variable
def job_folder = 'job_folder'
def job_name = 'job_name'
pipelineJob("${job_folder}/${job_name}") {
triggers {
gitlab {
repos:
- id: /.*/
# apply_requirements sets the Apply Requirements for all repos that match.
apply_requirements: [mergeable]
# workflow sets the workflow for all repos that match.
# This workflow must be defined in the workflows section.
allowed_overrides: [workflow]