Scriptler
Extended choice parameter
View...
import org.boon.Boon;
def jsonEditorOptions = Boon.fromJson(/{
disable_edit_json: false,
disable_properties: false,
no_additional_properties: false,
disable_collapse: true,
disable_array_add: false,
disable_array_delete: false,
disable_array_reorder: true,
theme: "bootstrap3",
iconlib:"bootstrap3",
schema: {
"title": "Delivery Files Parameters",
"type": "array",
"format": "table",
"uniqueItems": false,
"items": {
"type": "object",
"title": "Package",
"properties": {
"Module": {
"type": "string",
"propertyOrder": 1,
"default": ""
},"Version": {
"type": "string",
"propertyOrder": 2,
"default": ""
},"FileName": {
"type": "string",
"propertyOrder": 3,
"default": ""
}
}
}
}
}/);
return jsonEditorOptions;
Extended parameter - multiple choices
View...
import org.boon.Boon;
def jsonEditorOptions = Boon.fromJson(/{
disable_edit_json: false,
disable_properties: false,
no_additional_properties: false,
disable_collapse: true,
disable_array_add: false,
disable_array_delete: false,
disable_array_reorder: true,
theme: "bootstrap3",
iconlib:"bootstrap3",
schema: {
"title": "Delivery Files Parameters",
"type": "array",
"format": "table",
"uniqueItems": false,
"items": {
"type": "object",
"title": "package",
"properties": {
"file_source":{
"type": "string",
"propertyOrder": 1,
"format": "file",
"media":
{ "binaryEncoding": "base64" }
},"file_name": {
"type": "string",
"propertyOrder": 2,
"default": ""
},"module_name": {
"type": "string",
"propertyOrder": 3,
"enum": ["seenaddr", "seenadm", "seenord", "seenself", "selfcare","seenserv"]
}
}
}
}
}/);
return jsonEditorOptions;
Get Variables
Manage credentials ...
def envVars = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars()
def GOGS_CMD = "${envVars['GOGS_USER']}@${envVars['GOGS_SERVER']}:${envVars['GOGS_REPO']}"
def slurper = new JsonSlurper().parseText(jsonDelivery)
slurper.each{ ou slurper.items.each{ ##depend du json
// Get credential
import hudson.model.*
import groovy.json.JsonSlurper
import jenkins.model.JenkinsLocationConfiguration
import jenkins.model.Jenkins
import com.cloudbees.plugins.credentials.*
//get credential
def utility = new GroovyScriptEngine( '.' ).with {
loadScriptByName(Jenkins.instance.getRootDir().toString() + '/scriptler/scripts/Utility.groovy') //Utilility.groovy un autre fichier
}
this.metaClass.mixin utility
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,Jenkins.instance,null,null);
def userAPI = getUserbyID(creds, 'xxxxxxxxxxxxxxxxx')
def tokensApi = getPasswordbyId(creds, 'xxxxxxxxxxxxxxxxx')
def apijenkins = userAPI+':'+tokensApi
Change directory - cd
# cd in /tmp/ to run a script
cmd= "ls"
def cmddir = new File("/tmp/")
cmd.execute(null, cmddir).text
env...
import groovy.json.*
import hudson.model.*
import java.util.*;
// get env variables
def env = System.getenv();
def workspace = env['WORKSPACE'];
//store variables 'Packages in json file'
def jsonFile = new File(env['Packages']); //a
def jsonDelivery = jsonFile.readLines(); //b
def slurper = new JsonSlurper().parseText(jsonDelivery); //c
// ligne a et b sont de trop ici(unitile de remettre dans un fichier)
//ainsi c= def slurper = new JsonSlurper().parseText(env['Packages']);
def appli_name = env['Application'];
if (appli_name == null){
println(' ')
println('Please choose an application before building this job')
System.exit(1)
}
//decode uploaded files
slurper.each{
println(it)
}