Skip to content

Instantly share code, notes, and snippets.

View matthiasbaldi's full-sized avatar

Matthias Baldi matthiasbaldi

View GitHub Profile
// this script can be used to change the JDK for multiple Jenkins Jobs
// to use the script, edit the variables and run it in the Jenkins Script Console
// please set the variable value
def jobNameWithCorrectJdk = "" // set a JobName with the correct JDK
def jdkToChange = "JDK[JDK 1.8]" // set the JDK you want to change
def partOfJobNameToSearch = "" // set a part of the job name to generate the list of jobs
// script - here you have nothing to edit
def newJdk = Jenkins.instance.getItemByFullName(jobNameWithCorrectJdk).JDK
@matthiasbaldi
matthiasbaldi / removeWindows10Apps.ps1
Created September 12, 2016 19:58
remove preinstalled Windows 10 apps
# Uninstall 3D Builder:
Get-AppxPackage *3dbuilder* | Remove-AppxPackage
# Uninstall Alarms and Clock:
Get-AppxPackage *windowsalarms* | Remove-AppxPackage
# Uninstall Calculator:
Get-AppxPackage *windowscalculator* | Remove-AppxPackage
# Uninstall Calendar and Mail:
Get-AppxPackage *windowscommunicationsapps* | Remove-AppxPackage
# Uninstall Camera:
Get-AppxPackage *windowscamera* | Remove-AppxPackage
@matthiasbaldi
matthiasbaldi / jenkinsJobConfigReload.groovy
Last active September 20, 2016 07:27
Reload Jenkins Job
// inspired by https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/reloadJobConfig.groovy
// by Matthias Baldi @2016
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream
import javax.xml.transform.stream.StreamSource
// load job and configuration
def job = Jenkins.instance.getItemByFullName("PA-ISA-APIs-admin")
@matthiasbaldi
matthiasbaldi / jenkinsJobMatchHelperByJobName.groovy
Created September 20, 2016 08:18
Jenkins Matching Helper for other Jenkins Groovy Scripts
// please set the variable value
def partOfJobNameToSearch = "" // set a part of the job name to generate the list of jobs
// script - here you have nothing to edit
def totCounter = 0
def okCounter = 0
def badCounter = 0
for (item in Jenkins.instance.items) {
totCounter++
if (item.name.toLowerCase().contains(partOfJobNameToSearch.toLowerCase())) {
@matthiasbaldi
matthiasbaldi / multipleJenkinsJobConfigUpdate.groovy
Created September 20, 2016 08:24
Update multiple Jenkins job configurations by specific XML property
// this script can be used to change a specific XML property of the Jenkins config.xml of a job
// to use the script, edit the variables and run it in the Jenkins Script Console
import hudson.model.*
import jenkins.model.Jenkins
import java.io.File;
import groovy.xml.XmlUtil
import static javax.xml.xpath.XPathConstants.*
import groovy.xml.DOMBuilder
import groovy.xml.dom.DOMCategory
@matthiasbaldi
matthiasbaldi / deactivateJenkinsCSP.groovy
Last active January 21, 2022 20:43
Deactivate Jenkins Content Security Policy
// https://wiki.jenkins-ci.org/display/JENKINS/Configuring+Content+Security+Policy
// this line of code you can enter in your script console jenkinsserver.io/script
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
// or perisistent with this start param
-Dhudson.model.DirectoryBrowserSupport.CSP="default-src 'self'; script-src '*'; connect-src '*'; img-src '*'; style-src '*';"
@matthiasbaldi
matthiasbaldi / Jenkinsfile
Created February 15, 2017 16:40
load groovy file/lib into Jenkinsfile
node(label) {
step([$class: 'WsCleanup'])
sh "wget -O ./pipeline.lib.groovy https://github.com/<url>/pipeline.lib.groovy"
def pipelineLib = load 'pipeline.lib.groovy'
pipelineLib.checkoutSource(<your params>)
pipelineLib.buildProject(<your params>)
pipelineLib.publishArtifacts(<your params>)
pipelineLib.archiveArtifacts(<your params>)
@matthiasbaldi
matthiasbaldi / gist:05a50be24185616e763c1961f1d5ad1b
Created September 8, 2017 18:49
Convert VMWare VMDK to HyperV VHDX
// credits to:
// http://www.askme4tech.com/how-convert-vmware-virtual-machine-hyper-v
1. Install Microsoft Virtual Machine Converter
2. Open Powershell as Administrator
// Enter command
3. Import-Module "C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1"
// https://stackoverflow.com/questions/37481737/error-when-converting-vmware-virtual-disk-to-hyperv
4. Edit the VMWare vmdk file in a text editor and remove the complete "The Disk Data Base"
// Fix path's and enter command
// delete all lockable ressources
def res = GlobalConfiguration.all().get(org.jenkins.plugins.lockableresources.LockableResourcesManager.class).resources
res.retainAll {it -> it.locked || it.labelsContain('handmade')}
@matthiasbaldi
matthiasbaldi / PeriodicFolderTrigger.groovy
Created August 20, 2018 08:54
Jenkins set PeriodicFolderTrigger for multiple Items
def counter = 0
for (f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class)) {
if (f.parent instanceof jenkins.branch.OrganizationFolder) {
// managed by org folder, leave alone
continue;
}
if (f.name.matches(/.*api.*/)) {
println "set config for: ${f.name}"
// addTrigger will replace an existing one
f.addTrigger(new com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger("30m"));