Skip to content

Instantly share code, notes, and snippets.

@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
@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: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 / 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 / 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 / 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 / gist:6d4085e50c1bcadcba7252b8c147fac7
Created November 23, 2018 16:02
get and filter git branch in jenkins pipeline
stage("git remote"){
withCredentials([usernamePassword(credentialsId: 'git_worker', passwordVariable: 'PASS', usernameVariable: 'USERNAME')]) {
String filterBranch = "release/"
String sh_git_result = sh(script: "git ls-remote http://${USERNAME}:${PASS}@bitbucket.yourdomain.com/scm/rpl/client.git | grep ${filterBranch}", returnStdout: true).trim()
println sh_git_result
//regex to take only `release/01.02` from `refs/heads/release/01.02-fake-239` - (?<=heads\/).*(?<=\d{2}\.\d{2})
// to take only `release/*` -> (?<=heads\/).*
branch_result = (sh_git_result =~ /(?<=heads\/).*/)[0]
Multibranch projects relationships
to get the scrumb:
http://Jenkins_User:Jenkins_User_Secret_like_6f9dd2bf8e2a5e737d296@YourJenkinsHost:8080/crumbIssuer/api/xml?xpath=/*/crumb/text()
trigger Jenkins multibranch project from bitbucket:
Bitbucket side
@Sysa
Sysa / README.md
Created March 11, 2019 11:19 — forked from datagrok/README.md
What happens when you cancel a Jenkins job

When you cancel a Jenkins job

Unfinished draft; do not use until this notice is removed.

We were seeing some unexpected behavior in the processes that Jenkins launches when the Jenkins user clicks "cancel" on their job. Unexpected behaviors like:

  • apparently stale lockfiles and pidfiles
  • overlapping processes
  • jobs apparently ending without performing cleanup tasks
  • jobs continuing to run after being reported "aborted"
@Sysa
Sysa / Git_tips_cheatsheet
Last active November 7, 2024 12:41
Git_tips
Working with your repository
I just want to clone this repository
If you want to simply clone this empty repository then run this command in your terminal.
git clone http://localhost:7990/scm/tes/mytestrepo.git
My code is ready to be pushed
If you already have code ready to be pushed to this repository then run this in your terminal.