choice equivalent in Jenkins scripted pipeline - variables

I recently refactored my declartive pipeline into a scripted form. Even if everything seems to work fine, I have a problem coming from the initialization of a multiple valued paramenter.
In my declarative pipeline, I was using the following definition of multiple valued parameter (which was working as it should):
parameters {
choice(choices: ['fix', 'major', 'minor', 'none'], description: "Increase version's number: MAJOR.MINOR.FIX", name: "VERSIONING")
}
I refactored it into this form for the scripted pipeline:
properties([
parameters([
choice(choices: ['fix\nmajor\nminor\nnone'], description: "Increase version's number: MAJOR.MINOR.FIX", name: "VERSIONING"),
]),
])
The problem is that when I realised that something wasn't working as it should, and printed the variable value with a sh """echo "Versioning parameter check:" ${params.VERSIONING}""" step, I got this from the Jenkins' console:
Versioning parameter check: false
Which is both a value not in the list, and of a different type (boolean instead of string).
Is there a way to implement multiple value parameter initialization in Jenkins scripted pipelines?
Why this directive doesn't work out of the box in the scripted pipeline, whereas it does in the declarative type?
Is this a bug or am I doing something wrong?

Your definition is absolutely fine. You just need to pass the choices as list items and not as \n seperated values.
properties([
parameters([
choice(choices: ['fix', 'major', 'minor', 'none'], description: "Increase version's number: MAJOR.MINOR.FIX", name: "VERSIONING"),
])
])

Try the other option for defining choice parameter:
properties([
parameters([
[$class: 'ChoiceParameterDefinition',
choices: 'fix\nmajor\nminor\nnone\n',
name: 'VERSIONING',
description: "Increase version's number: MAJOR.MINOR.FIX"
],
]),
])

We use the following for a choice parameter, so it looks like your own definition but without the brackets:
properties([
parameters([
choice(choices: 'fix\nmajor\nminor\nnone', description: "Increase version's number: MAJOR.MINOR.FIX", name: "VERSIONING"),
]),
])
If you want the default value to be empty, just add an empty first choice like this:
choice(choices: '\nfix\nmajor\nminor\nnone'

Related

Target specific field in Spectral schema rule

I have a rule with a schema function. The rule works fine in that it's identifying the problem, but it's also highlighting the entire object that fails the schema. Instead, I'd like it to highlight just the specific field inside the object that's causing the problem.
I've tried adding the field property, but that just causes the rule to not run (without error).
if-without-then-or-else:
description: if requires then or else.
severity: error
given:
- $
- $..[?(#.if)]
then:
- function: schema
functionOptions:
schema:
if:
required:
- if
then:
anyOf:
- required:
- then
- required:
- else
{
"if": {}
}
I ended up inverting the schema so that it tests the other way around.
if-requires-then-or-else:
description: 'The `if` keyword will be ignored unless an adjacent `then` and/or `else` keyword is present.'
severity: error
given:
- $
- $..[?(#.if)]
then:
- function: schema
functionOptions:
schema:
if:
not:
anyOf:
- required:
- then
- required:
- else
then:
properties:
if: false
It's basically saying, "If either then or else are not present, then if is also disallowed.
This way, it targets the if as the thing that shouldn't be there.

How to give names to MobX flows

How do I give a name to my flows?
I currently see messages in the console (using dev tools) like:
action '<unnamed flow> - runid: 3 - init'
index.js:1 action '<unnamed flow> - runid: 3 - yield 0'
My code (in typescript):
fetchMetricData = flow( function * (this: MetricDataStore) {
const responseJson:IMetrics[] = yield Http.post("/metrics");
this.metrics = responseJson;
});
According to following text found in MobX Api Reference · MobX page:
Tip: it is recommended to give the generator function a name, this is the name that will show up in dev tools and such
Unfortunately, this is the only way to set the name (I use LiveScript and can't set names to function expressions while defining it).
In your case, you can turn your unnamed function expression into a named one. If you ever face another situation where you can't, you could also use Object.defineProperty(myFunction, 'name', {value: 'myExplicitName'}).
You can find the culprit in the code: mobx/flow.ts at master · mobxjs/mobx.

RedisGraph - Combining multiple directives with MERGE

I am currently running the below query on Neo4J
match (p:Initial{state: 'Initial', name: 'Initial'}), (c:Encounter{code:'abcd', state: 'Encounter', name: 'Encounter1'})
merge (p)-[:raw {person_id:'1234', type:'Encounter', code:'abcd'}]->(c)
However I am unable to do the same query on RedisGraph.
According to what I have found so far, Redis does not seem to support combining MERGEwith other directives
Is there any workaround to this?
Can the query be changed to allow it to execute the same functionality without the match statement?
The only option I see right now is to split this into two queries,
The first one checks to see if p is connected to c:
MATCH (p:Initial{state: 'Initial', name: 'Initial'})-[:raw {person_id:'1234', type:'Encounter', code:'abcd'}]->(c:Encounter{code:'abcd', state: 'Encounter', name: 'Encounter1'}) RETURN p,c
If the above query returns empty issue a second query to form the relation:
MATCH (p:Initial{state: 'Initial', name: 'Initial'})(c:Encounter{code:'abcd', state: 'Encounter', name: 'Encounter1'}) CREATE (p)-[:raw {person_id:'1234', type:'Encounter', code:'abcd'}]->(c)

Why is yadcf custom_filter not working?

Fiddle: https://codepen.io/MBaas/pen/rpZZzd
I have a Datatable about newspapers endorsements for presidential candidates that I want to filter on the party - a value that is not contained in the table (I have shortcodes "D" or "R" in the table but would like to use text "Democrat" or "Republican" in the UI).
This may have once worked (I think it did) - but after upgrading to beta 0.9.1 it stopped. Possibly a bug in the beta - or possibly an undetected bug in my code?
My fn:
function myCustomFilterFunction(filterVal,columnVal,rowValues,stateVal)
{
console.log(rowValues);
console.log(filterVal+'/'+columnVal);
if (columnVal === '') { return true;}
return -1 < columnVal.search(filterVal);
}
I had added the log for debugging purposes and it produced this output (excerpt):
["Wisconsin State Journal", "2016", "Clinton", "", "", "", ""]
"D/"
I was surprised to see columnVal being empty. That explained filtering not working, and it being empty can be explained by looking at rowValues. But given that the source-data was defined in JSON as
["Wisconsin State Journal",2016,"Clinton","http:\/\/host.madison.com\/wsj\/opinion\/editorial\/our-endorsement-hillary-clinton-america-must-get-this-right\/article_b526fe64-c2ca-5e3d-807a-0ef4ae23a4d5.html","","","D"]
this is odd. Could it be related to the fact that the column is not visible?
You should make column containing party short code searchable with searchable: true option otherwise your custom filtering function won't work.
For example:
{"searchable":true, "title":"Party (Shortcode)", "visible":true}
See updated example for code and demonstration.

Assign parameterised BigQuery magic to variable in Jupyter

How can I assign the output of a BigQuery cell magic operation in Jupyter if it has parameters?
%%bq execute --query sql_my_query --to-dataframe
parameters:
- name: min_val
type: STRING
value: $min_val
- name: max_val
type: STRING
value: $max_val
I've tried placing a variable in front of the BQ magic (e.g. myvar = %%bq ...), I've tried using myvar << %%bq, adding parentheses or braces around the entire expression but nothing seems to work. Does anyone have any ideas?
There are no examples in the examples either except with the Python API, which seems a bit messy for something that should be fairly standard.
You can define the query in one cell using the magic command.
But then to execute the query and supply the parameter values, do it in another cell without the magic command:
# in the first cell
%%bq query --name day_extract_query
SELECT EXTRACT(DAY FROM #input_date) AS day
After that, execute using pure python with no magic
# then, in a second cell
query_params1 = [{ "name": "input_date",
"parameterType": { "type": "DATE" },
"parameterValue": { "value": "2019-01-03" } }]
day1 = day_extract_query.execute(query_params=query_params1).result()