Skip to content

Instantly share code, notes, and snippets.

View imoutsatsos's full-sized avatar

Ioannis K. Moutsatsos imoutsatsos

  • Novartis (ioannis.moutsatsos@novartis.com)
  • Arlington, MA
  • X @ioannismou
View GitHub Profile
/*
How to get a task IDs from a qstat grid engine report civilized
qstat reports failed tasks as comma separated mixed list of task-IDs and range-like task-IDs
Example: '135-139:1,143,146,147'
We want to transform this to a civilized Array List like: [135, 136, 137, 138, 139, 143, 146, 147]
*/
mixedListRanges='135-139:1,143,146,147'
def failedTasks=mixedListRanges.tokenize(',').collect{qstatRangeToList(it)}.flatten()
def qstatRangeToList(String rangeString){
@imoutsatsos
imoutsatsos / pr.md
Created July 22, 2023 15:26 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

//Generated by ChatGPT
import jenkins.model.*
import hudson.model.*
import hudson.XmlFile
def jobName = "my-job"
def configFilePath = "/path/to/config.xml"
def jenkins = Jenkins.getInstance()
def configFile = new XmlFile(new File(configFilePath))
# As generated by ChatGPT-Does NOT work
# there is no 'User' option but can try 'Principal'
# Define the path to the Java executable and the arguments to pass to it
$javaPath = "C:\Program Files\Java\jre1.8.0_281\bin\java.exe"
$javaArgs = "-Dcantaloupe.config=cantaloupe.properties -Xmx2g -jar cantaloupe-5.0.5.war"
# Define the name of the scheduled task and the user account to run it as
$taskName = "Cantaloupe"
$taskUser = "DOMAIN\USERNAME"
#Generated by ChatGPT
$taskName = "Cantaloupe Task"
$actionArgs = "-Dcantaloupe.config=cantaloupe.properties -Xmx2g -jar cantaloupe-5.0.5.war"
$action = New-ScheduledTaskAction -Execute "java.exe" -Argument $actionArgs
$trigger = New-ScheduledTaskTrigger -Daily -At "3:00am"
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings
/*
Suggested by ChatGPT
Here's an example Groovy script that uses the `HttpURLConnection` class
to connect to a web service, send a JSON payload via HTTP POST, and record the response:
*/
import java.net.HttpURLConnection
import java.net.URL
// Define the URL of the web service
def url = new URL("http://example.com/myservice")
/*
Execute from the Jenkins script console
to delete offline Jenkins nodes
taken from answer at https://stackoverflow.com/a/48438012/2612175
*/
for (aSlave in hudson.model.Hudson.instance.slaves) {
if (aSlave.getComputer().isOffline()) {
aSlave.getComputer().setTemporarilyOffline(true,null);
aSlave.getComputer().doDoDelete();
}
/*
this function was suggested by ChatGPT AI
This function takes three parameters: the name of the Jenkins job to modify, the name of the existing parameter to rename, and the new name for the parameter.
It first retrieves the job object from the Jenkins instance, then looks for the ParametersDefinitionProperty for the job. If it doesn't find any parameters, or the specified parameter does not exist, it prints an error message and exits.
If the specified parameter exists, it creates a new parameter object with the new name and replaces the old parameter with the new one. Finally, it saves the job configuration to persist the changes.
You can call this function in a Jenkins pipeline or directly in the Jenkins script console.
*/
@imoutsatsos
imoutsatsos / jenkinsCLI_multiPlugin_Install.ps1
Created February 2, 2023 20:10
PowerShell script uses jenkins-cli to install multiple Jenkins plugins
#An example PowerShell build step of how to use jenkins-cli to install multiple Jenkins plugins
$condition = 'true'
$setupBase='D:\SERVER_SETUP\JENKINS' #Path to jenkins-cli.jar file
# A space separated list of Jenkins plugins to install, using their short names
$missing= 'jenkins-multijob-plugin parameterized-trigger' -split ' '
$USER_NAME='ioannis'
$JENKINS_API_TOKEN='blahblah'
@imoutsatsos
imoutsatsos / findAndRemapHttpURL.groovy
Last active December 14, 2021 01:01
Finds embedded URLs in a web page and remaps them to https scheme given a few limited logic rules
/*** BEGIN META {
"name" : "findAndRemapURL",
"comment" : "Finds embedded URLs in a web page and remaps them to https scheme given a few limited logic rules",
"parameters" : [ 'vWebPageUrl','viiifCurrentPort','viiifRemapPort'],
"core": "2.222.1",
"authors" : [
{ name : "Ioannis K. Moutsatsos" }
]
} END META**/