How to set multipe values in CascadeChoiceParameter's for referencedParameters - groovy

Trying to set multiple values in CascadeChoiceParameter's for referencedParameters. What the format should be? Docs documentation said that it should be 'string', but in case of setting referencedParameters: 'param1,param2' it goes to fallback script.
here is the class:
[$class: 'CascadeChoiceParameter',
name: 'SOME_PARAM',
description: 'some description',
randomName: '',
script: [$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["item_1"]'
],
script: [
classpath: [],
sandbox: true,
script: """
if(PARAM_2.equals("some_value") && PARAM_3.equals("some_value")) {
return ["item_1", "item_2", "item_3"]
} else if((PARAM_2.equals("E2E_Tests") || (PARAM_2.equals("Real_API")) && PARAM_3.equals("knox_guard")) {
return ["item_1", "item_2", "item_4"]
} else {
return ["item_1"]
}
""".stripIndent()
]
],
choiceType: 'PT_SINGLE_SELECT',
referencedParameters: 'PARAM_2,PARAM_3',
filterable: false,
filterLength: 1
],

The fallback script is used if/when there is any kind of exception/error when attempting to execute the main script. In your case, there is a compilation error in the else if((PARAM_2.equals("E2E_Tests") || (PARAM_2.equals("Real_API")) && PARAM_3.equals("knox_guard")) line. All the open parenthesis haven't been closed - there are 6 open parenthesis and only 5 close parenthesis. Anyway, I haven't tested a CascadeChoiceParameter version of the pipeline. I have tested using activeChoiceReactiveParam. Below is a working job DSL:
String choicesScript = """
if(PARAM_2.equals("some_value") && PARAM_3.equals("some_value")) {
return ["item_1", "item_2", "item_3"]
} else if((PARAM_2.equals("E2E_Tests") || (PARAM_2.equals("Real_API")) && PARAM_3.equals("knox_guard"))) {
return ["item_1", "item_2", "item_4"]
} else {
return ["item_5"]
}
""".stripIndent()
String pipeline = '''
pipeline {
agent any
stages {
stage('Show parameter values') {
steps {
echo "PARAM_2: ${params.PARAM_2}, PARAM_3: ${params.PARAM_3}, SOME_PARAM: ${params.SOME_PARAM}"
}
}
}
}
'''.stripIndent()
pipelineJob('reactive-params') {
parameters {
activeChoiceParam('PARAM_2') {
description('First test parameter')
choiceType('SINGLE_SELECT')
groovyScript {
script('return ["some_value", "E2E_Tests", "Real_API"]')
}
}
activeChoiceParam('PARAM_3') {
description('Second test parameter')
choiceType('SINGLE_SELECT')
groovyScript {
script('return ["some_value", "knox_guard"]')
}
}
activeChoiceReactiveParam('SOME_PARAM') {
description('some description')
choiceType('SINGLE_SELECT')
referencedParameter('PARAM_2')
referencedParameter('PARAM_3')
groovyScript {
script(choicesScript)
fallbackScript('return ["item_1"]')
}
}
}
definition {
cps {
script(pipeline)
}
}
}

Related

mutation syntax error : grapgql update string

here is my mutation . that was working fine . from yesterday it throw error on condition key
condition: "{\"data\":{\"a\":{\"source\":\"ENTITY_STATE\",\"id\":\"4b026027-7458-4ba4-9079-f3dd4f16b65b\"}},\"rules\":{\"==\":[{\"var\":\"a.on\"},false]}}"
here is my full mutation :
mutation {
rule {
create(
input: {
name: "After every minute ?"
description: "Will turn on device after every minute"
triggers: [
{
name: "TimeTrigger"
options: {
cron: "* * * * 1"
# time: "after 10 seconds"
}
}
]
condition: "{\"data\":{\"a\":{\"source\":\"ENTITY_STATE\",\"id\":\"4b026027-7458-4ba4-9079-f3dd4f16b65b\"}},\"rules\":{\"==\":[{\"var\":\"a.on\"},false]}}"
actions: [
{
name: "EntitySetStateAction"
options: {
entityId: "4b026027-7458-4ba4-9079-f3dd4f16b65b"
state: "{\"on\": true,\"thermostat.mode\": \"cool\",\"thermostat.setpoint\": 20,\"fanSpeed.mode\": \"high\"}"
# state: {on: true}
}
}
]
}
) {
id
embedded
name
description
active
actions {
options
} # triggers
# condition {rulenes data}
# triggers
}
}
}

Extract a list of profileId's using jsonpath

I have the following JSON object r2,
[
{
"reserva_id":"200",
"estancias":[
{
"reserva_estancia":"266",
"huespedes":[
{
"reserva_huesped":"272",
"reserva_estancia":"266",
"numero_huesped":"1",
"huesped":"123",
"huesped_nombre":"dos dos, dos",
"rfid":null
},
{
"reserva_huesped":"276",
"reserva_estancia":"266",
"numero_huesped":"2",
"huesped":"183",
"huesped_nombre":"MUESTRA MUESTRA, CARMEN",
"rfid":null
}
]
}
]
},
{
"reserva_id":"201",
"estancias":[
{
"huespedes":[
{
"reserva_huesped":"273",
"reserva_estancia":"267",
"numero_huesped":"1",
"huesped":"148",
"huesped_nombre":"MUESTRA MUESTRA, CARMEN",
"rfid":null
},
{
"reserva_huesped":"277",
"reserva_estancia":"267",
"numero_huesped":"2",
"huesped":"187",
"huesped_nombre":"TEST TEST, TESTCIVITFUN",
"rfid":null
}
]
}
]
}
]
I am trying to get the first huesped for each reservation, and for that I am using the following script, to create a list called profiles and store profileId's:
def profiles = jsonpath(r2,'$..[:].estancias[:].huespedes[0].huesped')
The output should be the following:
[
"123",
"148"
]
However, when I print profiles.text I get all the content of the estancias object, instead of just the huesped number.
When using Jayway's JSONPath like this I get the desired oputput:
$..[*].estancias[*].huespedes[0].huesped
You can try the path expression with your JSON here online.

Terraform Json conditional creation

I`m trying to create json template file for emr security configuration. Currently I have the following:
resource "aws_emr_security_configuration" "this" {
name = "test-configuration"
configuration = jsonencode({
"EncryptionConfiguration": {
"EnableInTransitEncryption": var.intransitencryption_enabled,
"EnableAtRestEncryption": var.atrestencryption_enabled
"InTransitEncryptionConfiguration": {
"TLSCertificateConfiguration": {
"CertificateProviderType": "PEM",
"S3Object": var.s3_object
}
},
"AtRestEncryptionConfiguration": {
"S3EncryptionConfiguration": {
"EncryptionMode": "SSE-KMS",
"AwsKmsKey": var.kms_key_arn
},
"LocalDiskEncryptionConfiguration": {
"EnableEbsEncryption": true,
"EncryptionKeyProviderType": "AwsKms",
"AwsKmsKey": var.kms_key_arn
}
}
}
})
}
I want depends on var.intransitencryption_enabled variable (true or false) add or remove the following part:
"InTransitEncryptionConfiguration": {
"TLSCertificateConfiguration": {
"CertificateProviderType": "PEM",
"S3Object": var.s3_object
}
}
I tried
%{ if var.intransitencryption_enabled}
"InTransitEncryptionConfiguration": {
"TLSCertificateConfiguration": {
"CertificateProviderType": "PEM",
"S3Object": var.s3_object
}
}
{endif}
But it does not work. Does terraform have a valid decision to do that?

pass array to the puppet resource defined

I would like to test if multiple packages exist in my environment or not, based on this test I would like to generate the final catalog.
if !defined( Package[ 'apache2' ] ) {
package { 'apache2':
ensure => installed,
}
}
if !defined( Package[ 'libapache2-svn' ] ) {
package { 'libapache2-svn':
ensure => installed,
}
}
In future I would like to control in the following way:
Package { ensure => "installed" }
$packageList = [ 'apache2', 'libapache2-svn' ]
if !defined( Package[ $packageList ] ) {
package { $packageList: }
}

Groovy - How to simplify embedded function arguments

I am running groovy in jenkins and I want to split the data from the functionality. I've tried to create a map with variable names and values but it looks like functions inside functions screws that up. I want to pull out CurrentBuildNo, ProjectName, Results_Folder (they are different for each parallel run) without duplicating code.
autotests = parallel (
{ ignore(ABORTED) {
retry ( 2 ) {
build("AutoTest", CurrentBuildNo: CurrentBuildNo, ProjectName: params["ProjectName"], Results_Folder: Results_Folder)
} } },
{ ignore(ABORTED) {
retry ( 2 ) {
build("AutoTest", CurrentBuildNo: CurrentBuildNo, ProjectName: params["ProjectName"], Results_Folder: Results_Folder)
} } }
)
The logic I want is something like:
tests = {{CurrentBuildNo: CurrentBuildNo, ...},{CurrentBuildNo: CurrentBuildNo, ...}}
autotests = parallel (
for (i in tests){
ignore(ABORTED) {
retry ( 2 ) {
build("AutoTest", test[i]['CurrentBuildNo'], test[i]['ProjectName']...)
} } }
}
)
Ahhh, I think you'll want something like this:
def tests = [ [ CurrentBuildNo: CurrentBuildNo, ... ],
[ CurrentBuildNo: CurrentBuildNo, ... ] ]
parallel tests.collect { t ->
{
ignore( ABORTED ) {
retry( 2 ) {
build( 'AutoTest', t.CurrentBuildNo, ... )
}
}
}
}

Resources