Skip to content

Instantly share code, notes, and snippets.

@Sysa
Sysa / gist:6b452a320eb4b9004b407f1b1866ba59
Created November 16, 2018 13:49
jenkins get last successful build parameters
//jenkins get last successful build parameters
node("master"){
//get `branch` parameter of jenkins build
String sh_curl_result = sh(script: "curl -u your_jenkins_user:your_secret_API_key 'http://jenkinsInstance:8080/job/Project/job/job_name_deploy_all/lastSuccessfulBuild/api/xml?tree=actions\\[parameters\\[name,value\\]\\]&xpath=/workflowRun/action/parameter\\[name=%22Branch%22\\]/value'", returnStdout: true).trim()
println sh_curl_result
//string() is not supported by jenkins xpath XML api, so need to cut `value` tags it via regex:
result = (sh_curl_result =~ /(?<=>).*(?=<)/)[0]
println result
}
@Sysa
Sysa / jenkins-notes.md
Created September 28, 2018 07:56 — forked from misterbrownlee/jenkins-notes.md
Jenkins setup

I just had to set up Jenkins to use GitHub. My notes (to myself, mostly):

Detailed Instructions

For setting up Jenkins to build GitHub projects. This assumes some ability to manage Jenkins, use the command line, set up a utility LDAP account, etc. Please share or improve this Gist as needed.

Install Jenkins Plugins

@Sysa
Sysa / cleanupUnusedWorkspaceInSlaves.groovy
Last active September 4, 2018 14:14 — forked from ceilfors/cleanupUnusedWorkspaceInSlaves.groovy
When you delete jobs in Jenkins, the corresponding workspaces in the build slaves won't be deleted automatically. This Jenkins script will go to each slave and check if the jobs are already deleted in Jenkins master and delete the workspace.
import com.cloudbees.hudson.plugins.folder.Folder
import hudson.FilePath
import jenkins.model.Jenkins
def boolean isFolder(String name) {
def item = Jenkins.instance.getItemByFullName(name)
return item instanceof Folder
}
def deleteUnusedWorkspace(FilePath root, String path) {
@Sysa
Sysa / gist:7e19355ad5438950445618ddadd8e0c9
Last active September 26, 2018 17:06 — forked from rb2k/gist:8372402
A jenkins script to clean up workspaces on slaves
import hudson.model.*;
import hudson.util.*;
import jenkins.model.*;
import hudson.FilePath.FileCallable;
import hudson.slaves.OfflineCause;
import hudson.node_monitors.*;
hosts = getProperty('HostsForCleanup')
hosts = hosts.split("\n")
EmailToReport = getProperty('EmailToReport')
@Sysa
Sysa / git-feature-workflow.md
Created August 28, 2018 10:58 — forked from blackfalcon/git-feature-workflow.md
Git basics - a general workflow

There are many Git workflows out there, I heavily suggest also reading the atlassian.com [Git Workflow][article] article as there is more detail then presented here.

The two prevailing workflows are [Gitflow][gitflow] and [feature branches][feature]. IMHO, being more of a subscriber to continuous integration, I feel that the feature branch workflow is better suited.

When using Bash in the command line, it leaves a bit to be desired when it comes to awareness of state. I would suggest following these instructions on [setting up GIT Bash autocompletion][git-auto].

Basic branching

When working with a centralized workflow the concepts are simple, master represented the official history and is always deployable. With each now scope of work, aka feature, the developer is to create a new branch. For clarity, make sure to use descriptive names like transaction-fail-message or github-oauth for your branches.

@Sysa
Sysa / gist:0c3b54e4f3bb8845b88b21c41bf7e3ba
Last active August 23, 2018 13:38
Access to parameters in Jenkins project into pipeline script with getProperty(name)
To avoid `Scripts not permitted to use method` %groovy.lang.GroovyObject getProperty java.lang.String% for example during pipeline script execution,
need to approve the following signatures:
to approve:
method groovy.lang.GroovyObject getProperty java.lang.String
method hudson.model.ItemGroup getItem java.lang.String
method hudson.model.Job getAllProperties
method hudson.model.Job getProperties
method hudson.model.Job getProperty java.lang.String
method hudson.model.User getProperty java.lang.Class