{ ... script { ....
if (isStartedByUser) {
try {
timeout(time: 60, unit: 'SECONDS') {
def userInput = input(
id: 'userInput', message: 'Please Enter Environment', parameters:
[choice(name: 'environment', choices: tf.join("\n"), description: 'Choose environment you want to deploy this build'),
choice(name: 'debuglevel', choices: "\nINFO\nTRACE\nDEBUG\nWARN\nERROR", description: 'Choose debug level')
]
)
mydir = userInput['environment']
here
I have this in a Jenkins pipeline. tf is a List imported from a json.
Currently this code snippet only allows a single choice to be selected. I would like to be able to select multiple choices for the environment drop down selector.
Ok, So now I have this and it works! but need a slight optimization:
def multiSelect= new ExtendedChoiceParameterDefinition("Envs",
"PT_MULTI_SELECT",
tf.join(","),
"project name",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
tf.join(","),
"",
"",
"",
"",
"",
"",
"",
"",
false,
false,
15,
"Available Environments",
",")
def userInput = input(
id: 'userInput', message: 'Please Select terraform params', parameters:
[multiSelect]
)
def userInput2 = input(
id: 'userInput', message: 'Please Select terraform params', parameters:
[choice(name: 'debuglevel', choices: "\nINFO\nTRACE\nDEBUG\nWARN\nERROR", description: 'Choose debug level')
]
)
terraformdir = userInput.split(',')
println "dir ${terraformdir}"
env.TF_LOG = userInput2['debuglevel']
I was hoping to get both inputs on the same screen.
When I did
def userInput = input(
id: 'userInput', message: 'Please Select terraform params', parameters:
[multiSelect,
choice(name: 'debuglevel', choices: "\nINFO\nTRACE\nDEBUG\nWARN\nERROR", description: 'Choose debug level')
]
)
I wasn't sure how to access the value of multiSelect.
Yes, you should be able to, take a look at the example here. Following is a sample Declarative Pipeline.
import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition
def multiSelect= new ExtendedChoiceParameterDefinition("name",
"PT_MULTI_SELECT",
"blue,green,yellow,blue",
"project name",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"blue,green,yellow,blue",
"",
"",
"",
"",
"",
"",
"",
"",
false,
false,
3,
"multiselect",
",")
pipeline {
agent any
stages {
stage('Hello') {
steps {
script {
def userInput = input id: 'customID', message: 'Let\'s promote?', ok: 'Release!', parameters: [multiSelect]
}
echo 'Hello World'
}
}
}
}
Related
I have a string '["", "abc", "", "def", "", "mno", "", "", "", "", ""]'. i want to convert it into array and remove empty values from that array. my desired output is abc;def;mno.
Can someone help me to do this?
You could use JSON.parse and select method:
str = '["", "abc", "", "def", "", "mno", "", "", "", "", ""]'
arr = JSON.parse(str).select(&:present?)
Output array: ["abc", "def", "mno"]
If you want to get abc;def;mno:
joined = arr.join(';')
Output string: "abc;def;mno"
Hope this helps
Use this code:
str = YAML.load('["", "abc", "", "def", "", "mno", "", "", "", "", ""]')
str.select{|a| a if a != ""}.join(";")
You can parse your string with JSON#parse and use delete with join:
str = '["", "abc", "", "def", "", "mno", "", "", "", "", ""]'
JSON.parse(str).tap { |arr| arr.delete('') }.join(';')
# => "abc;def;mno"
I currently have an odata service with 2 entity sets. I am using expand to navigate to second entity set, and binding values from both in a table.
However, I am unable to bind data from second entity set as {to_PurchaseOrderItem/PurchaseOrderQuantityUnit}
Am I doing this wrong?
The JSON reply looks something like this, so I am really confused what I am doing wrong.
"d": {
"results": [
{
"PurchaseOrder": "4500000001",
"Language": "EN",
"PaymentTerms": "0004",
"CashDiscount1Days": "0",
"CashDiscount2Days": "0",
"NetPaymentDays": "0",
"CashDiscount1Percent": "0.000",
"CashDiscount2Percent": "0.000",
"PurchasingOrganization": "1710",
"PurchasingDocumentOrigin": "9",
"PurchasingGroup": "001",
"CompanyCode": "1710",
"PurchaseOrderDate": "/Date(1468454400000)/",
"DocumentCurrency": "USD",
"ExchangeRate": "1.00000",
"ValidityStartDate": null,
"ValidityEndDate": null,
"SupplierQuotationExternalID": "",
"SupplierRespSalesPersonName": "",
"SupplierPhoneNumber": "",
"SupplyingSupplier": "",
"SupplyingPlant": "",
"PurchaseOrderType": "NB",
"IncotermsClassification": "",
"InvoicingParty": "17300001",
"ReleaseIsNotCompleted": false,
"PurchasingCompletenessStatus": false,
"IncotermsVersion": "",
"IncotermsLocation1": "",
"IncotermsLocation2": "",
"ManualSupplierAddressID": "",
"AddressCityName": "",
"AddressFaxNumber": "",
"PurchasingDocumentDeletionCode": "",
"AddressHouseNumber": "",
"AddressName": "",
"AddressPostalCode": "",
"AddressStreetName": "",
"AddressPhoneNumber": "",
"AddressRegion": "",
"AddressCountry": "",
"AddressCorrespondenceLanguage": "",
"PurchasingProcessingStatus": "02",
"CreatedByUser": "CB9980000025",
"CreationDate": "/Date(1468454400000)/",
"Supplier": "17300001",
"PurchaseOrderSubtype": "",
"to_PurchaseOrderItem": {
"results": [
{
"PurchaseOrder": "4500000001",
"OrderQuantity": "100",
"PurchaseOrderQuantityUnit": "ES",
"OrderPriceUnit": "ES",
"OrderPriceUnitToOrderUnitNmrtr": "1",
"OrdPriceUnitToOrderUnitDnmntr": "1",
"NetPriceAmount": "0.21",
"DocumentCurrency": "USD",
"NetPriceQuantity": "1",
"TaxCode": "",
"PriceIsToBePrinted": true,
"PurchaseOrderItem": "1",
"OverdelivTolrtdLmtRatioInPct": "10.0",
"UnlimitedOverdeliveryIsAllowed": false,
"UnderdelivTolrtdLmtRatioInPct": "10.0",
"ValuationType": "",
"IsCompletelyDelivered": false,
"IsFinallyInvoiced": false,
"PurchaseOrderItemCategory": "0",
"AccountAssignmentCategory": "",
"MultipleAcctAssgmtDistribution": "",
"PartialInvoiceDistribution": "",
"PurchasingDocumentDeletionCode": "L",
"GoodsReceiptIsExpected": true,
"GoodsReceiptIsNonValuated": false,
"InvoiceIsExpected": true,
"InvoiceIsGoodsReceiptBased": false,
"PurchaseContract": "",
"PurchaseContractItem": "0",
"Customer": "",
"ItemNetWeight": "0.000",
"ItemWeightUnit": "",
"TaxJurisdiction": "0508525201",
"PurchaseOrderItemText": "RAW15,PD",
"PricingDateControl": "",
"ItemVolume": "0.000",
"ItemVolumeUnit": "",
"SupplierConfirmationControlKey": "",
"IncotermsClassification": "EXW",
"IncotermsTransferLocation": "VENDOR",
"EvaldRcptSettlmtIsAllowed": false,
"PurchaseRequisition": "",
"PurchaseRequisitionItem": "0",
"IsReturnsItem": false,
"Plant": "1710",
"RequisitionerName": "",
"ServicePackage": "0",
"EarmarkedFunds": "",
"EarmarkedFundsItem": "0",
"IncotermsLocation1": "VENDOR",
"IncotermsLocation2": "",
"Material": "RM15",
"ManufacturerMaterial": "RM15",
"ServicePerformer": "",
"ProductType": "1",
"StorageLocation": "",
"DeliveryAddressID": "",
"DeliveryAddressName": "",
"DeliveryAddressStreetName": "",
"DeliveryAddressHouseNumber": "",
"DeliveryAddressCityName": "",
"DeliveryAddressPostalCode": "",
"DeliveryAddressRegion": "",
"DeliveryAddressCountry": "",
"MaterialGroup": "L002",
"PurchasingInfoRecord": "5300000201",
"SupplierMaterialNumber": ""
I am trying to access Order Quantity to be specific.
Thanks!
I think you are missing "results" while binding the control. Please see below and try
{to_PurchaseOrderItem/results/0/PurchaseOrderQuantityUnit}
I need to send this below parameters to a server in swift 3.0. How can I build the request parameters?
"step_1": [
{
"name": "",
"mobile": "",
"line_1": "",
"line_2": "",
"city": "",
"state": "",
"pincode": "",
"fax": "",
"gst": "",
"owner_name": "",
"dob": "",
"anniversary": ""
}
]
For upper json data below is Dictionary code:
let param = [["name": "abc",
"mobile": "123",
"line_1": "line_1",
"line_2": "line_2",
"city":"xyz",
"state":"abc",
"pincode":"000",
"fax":"123",
"gst":"gst",
"ownwer_name":"ownwer_name",
"dob":"xx-xx-xxxx",
"anniversary":"xx-xx-xxxx"]]
//Print data
print(param[0]["name"] as! String)
Hi I'm not sure if it will work, but anyway, try this
let params: ["step_1": [["name": "Some name",
"mobile": "12345678",
"line_1": "line_1 stuff",
"...": "..."]]]
I'm using the Active Choices Reactive Reference Parameter plugin in a dsl job here the code
parameters {
activeChoiceParam('choice1') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script("return['aaa','bbb']")
fallbackScript('return ["error"]')
}
}
activeChoiceReactiveParam('choice2') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script("if(choice1.equals("aaa")){return ['a', 'b']} else {return ['aaaaaa','fffffff']}")
fallbackScript('return ["error"]')
}
referencedParameter('choice1')
}
and it work's fine what i want now is how to use the activeChoiceReactiveParam in a jenkinsFile for pipeline job i did that :
properties(
[
[
$class : 'ParametersDefinitionProperty',
parameterDefinitions: [
[
$class : 'ChoiceParameterDefinition',
choices : 'aaa\nbbb',
description: 'select your choice : ',
name : 'choice1'
]
but how can i add the choice2 parameter !!!
I was in need of the similar solution.
I did not find any related answers/examples specific to Active Choices plugin anywhere in my google search.
With some R & D, finally I was able to get this done for a pipeline project.
Here is the Jenkinsfile code
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Env Name from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Env',
randomName: 'choice-parameter-5631314439613978',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Env\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return["Dev","QA","Stage","Prod"]'
]
]
],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Server from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Server',
randomName: 'choice-parameter-5631314456178619',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){
return["qaaaa001","qabbb002","qaccc003"]
}
else if(Env.equals("Stage")){
return["staaa001","stbbb002","stccc003"]
}
else if(Env.equals("Prod")){
return["praaa001","prbbb002","prccc003"]
}
'''
]
]
]
])
])
pipeline {
environment {
vari = ""
}
agent any
stages {
stage ("Example") {
steps {
script{
echo 'Hello'
echo "${params.Env}"
echo "${params.Server}"
if (params.Server.equals("Could not get Environment from Env Param")) {
echo "Must be the first build after Pipeline deployment. Aborting the build"
currentBuild.result = 'ABORTED'
return
}
echo "Crossed param validation"
} }
}
}
}
Even you can use "Active Choices Reactive Reference Parameter" with below definitions and rest of the code, follow as in above example.
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'These are the details in HTML format',
name: 'DetailsInHTML',
omitValueField: false,
randomName: 'choice-parameter-5633384460832175',
referencedParameters: 'Env, Server',
script: [
$class: 'ScriptlerScript',
parameters: [[$class: 'org.biouno.unochoice.model.ScriptlerScriptParameter', name: '', value: '$value']],
scriptlerScriptId: 'script.groovy'
]
]
Note: Ensure you have "," delimiter between multiple parameter definition blocks.
Hope this helps someone.
Instead of using the Active Choices Reactive Reference Parameter i did below and it's working fine !!!
node('slave') {
def choice1
def choice2
stage ('Select'){
choice1 = input( id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'aa\nbb', description: '', name: ''] ])
if(choice1.equals("aa")){
choice2 = input( id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'yy\nww', description: '', name: ''] ])
}else{
choice2 = input( id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'gg\nkk', description: '', name: ''] ])
}
}
}
Thanks a ton #Yogeesh. It helped a lot.
In my case, the requirement was to select multiple instead of one. So, used choiceType: 'PT_CHECKBOX', and it served the purpose.
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Env Name from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Env',
randomName: 'choice-parameter-5631314439613978',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Env\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return["Dev","QA","Stage","Prod"]'
]
]
],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select Servers',
filterLength: 1,
filterable: true,
name: 'Server',
randomName: 'choice-parameter-5631314456178619',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){
return["qaaaa001","qabbb002","qaccc003"]
}
else if(Env.equals("Stage")){
return["staaa001","stbbb002","stccc003"]
}
else if(Env.equals("Prod")){
return["praaa001","prbbb002","prccc003"]
}
'''
]
]
]
])
I made the initial sample work for me.
I had to change ' for " in the return statement return ["a", "b"] and " by ' in the script statement script(' ')
job("MyJob") {
description ("This job creates ....")
//def targetEnvironment=""
parameters {
activeChoiceParam('choice1') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script('return["aaa","bbb"]')
fallbackScript('return ["error"]')
}
}
activeChoiceReactiveParam('choice2') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script(' if(choice1.equals("aaa")) { return ["a", "b"] } else {return ["aaaaaa","fffffff"] } ')
fallbackScript('return ["error"]')
}
referencedParameter('choice1')
}
}
}
Is there any way that we can put the script logic in a function and call
for example:
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select Servers',
filterLength: 1,
filterable: true,
name: 'Server',
randomName: 'choice-parameter-5631314456178619',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){
return["qaaaa001","qabbb002","qaccc003"]
}
else if(Env.equals("Stage")){
return["staaa001","stbbb002","stccc003"]
}
else if(Env.equals("Prod")){
return["praaa001","prbbb002","prccc003"]
}
'''
]
]
]```
define below code in funciton and call ?
if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){ return["qaaaa001","qabbb002","qaccc003"] } else if(Env.equals("Stage")){ return["staaa001","stbbb002","stccc003"] } else if(Env.equals("Prod")){ return["praaa001","prbbb002","prccc003"]
}
Try something like that:
properties(
[
[
$class : 'ParametersDefinitionProperty',
parameterDefinitions: [
[
$class : 'ChoiceParameterDefinition',
choices : 'aaa\nbbb',
description: 'select your choice : ',
name : 'choice1'
],
[
$class : 'ChoiceParameterDefinition',
choices : 'ccc\nddd',
description: 'select another choice : ',
name : 'choice2'
]
Can some one please help me understand whats wrong with my Cypher query
MATCH (sys:System{Name:'MYSYS' , Version:'1.0'})
FOREACH (item in [
{
itemObj: {
ItemID: "DOMAIN",
Name: "DOMAIN",
TypeID: "",
Physical: "",
Logical: ""
},
parameters: {
VERSIONNUM: "",
QUALSTATE: "",
VERSION: "",
CREATEDBY: "",
DATECREATED: "",
MODIFIEDBY: "",
VERSIONDATE: "",
BLCKCOMMENT1: "",
BLCKCOMMENT2: "",
BLCKCOMMENT3: "",
BLCKCOMMENT4: "",
ORIGASSIGN: "",
CANETYPE: "",
FULLITEMNAME: "",
DESC: "",
SCANPNTDTL: "",
SCANASSOCDSP: "",
ADSIPATH: "",
ASSIGNABLE: ""
}
},
{
itemObj: {
ItemID: "COMPUTERS",
Name: "COMPUTERS",
TypeID: "",
Physical: "",
Logical: ""
},
parameters: {
VERSIONNUM: "",
QUALSTATE: "",
VERSION: "",
CREATEDBY: "",
DATECREATED: "",
MODIFIEDBY: "",
VERSIONDATE: "",
BLCKCOMMENT1: "",
BLCKCOMMENT2: "",
BLCKCOMMENT3: "",
BLCKCOMMENT4: "",
ORIGASSIGN: "",
CANETYPE: "",
FULLITEMNAME: "",
DESC: "",
SCANPNTDTL: "",
SCANASSOCDSP: "",
ASSIGNABLE: ""
}
},
{
itemObj: {
ItemID: ".htm",
Name: ".htm",
TypeID: "",
Physical: "",
Logical: ""
},
parameters: {
FileName: ""
}
}
] |
CREATE (p:Parameter) SET p=item.parameters
MERGE (it:Item { ItemID: item.itemObj.ItemID}) ON CREATE SET it=item.itemObj
MERGE (sys)-[HAS_ITEM]->(it)-[:HAS_PARAMETERS]->(p) )
I end up getting this error
A single relationship type must be specified for CREATE (line 77, column 12)
I am trying to learn to use foreach as its seams very fast in case of bulk insert, so any help here is really welcome.
Regards
Kiran
You are missing a : when declaring relationship type. On the last line, [HAS_ITEM] should be [:HAS_ITEM].