As part of automating a legacy deployment process, I'm trying to build a Jenkins pipeline that can, among other operations, execute parameterized builds.
One of those is the ability to execute several commands against given list of services. Given a list of service names, e.g.
Mailer
Reporter
DbMigrator
...
etc, I'd like to run certain commands against some of those.
Using Extended Choice Parameter plugin, I was able to load this list from a properties file, and display it as a list of checkboxes, however, I am looking for a way I could build a "matrix" parameter with multiple values. My goal is to do something like this:
| Service | Opt1| Opt2|
|------------------------|
| Mailer | [x] | [ ] |
| Reporter | [x] | [x] |
| DbMigrator | [ ] | [x] |
| ... | | |
So that I can apply several values (Opt1 and/or Opt2) to one parameter (e.g. Mailer).
Is there a way in Jenkins to do this?
or
Is there a better way of doing this?
You can try the matrix project plugin which comes bundled with later versions of Jenkins.
You can add a couple of groovy axis
which allows you to do this
import groovy.json.JsonSlurper
def result = []
def inputFile = new File("/path/to/prop.json")
def InputJSON = new JsonSlurper().parseText(inputFile.text)
InputJSON.prop1.each{ result << it }
return result
with this sort of JSON
{
"parm1": [
"Mailer",
"Reporter",
"DbMigrator"
],
"parm2": [
"opt1",
"opt2"
],
"filter": "parm1=='Mailer'"
}
These is also a filter option in the matrix to restrict to various combinations. I was trying to make it evaluate that from the 'filter' property above (creating an environment variable using the EnvInject and another groovy script), so far with no success but you can use a string
parm1=='Mailer' || parm2 = 'Opt2'
Related
Consider this query:
| makeresults count=100000
| eval a=if(random()%2==0,"apple", "banana")
| eval b=if(random()%2==0,"cherry","date")
| eval c=if(random()%2==0,"eggplant",if(random()%2==0,"fig",if(random()%2==0,"grape","huckleberry")))
| eval x=random()
| eval y=random()%x
What I'd like is to simply add:
| fit y from x by a, b, c
Then, I would get a total of n models (16 in this case) created and applied to the data, which I can then do stuff with.
Unfortunately, Splunk's fit command does not support a by clause.
The question is, how can I use the commands that ARE available to accomplish the same thing?
I've tried using map but that is limited to 10 subqueries.
I've tried using foreach but that complains: "Search pipeline may not contain non-streaming commands"
Are there commands available to me that will let me do what I'm trying to do?
I want to fetch data from my sql Table and use them as a choice parameters in Jenkins
+----+
| ID |
+----+
| 11 |
| 23 |
| 45 |
| 72 |
| 5 |
| 16 |
| 71 |
| 18 |
+----+
I want to use these IDs as a choice parameter in Jenkins in order to build using one of these ID i.e. build with parameters using these ID numbers as Parameter
I simply want a drop down with these ID numbers as the choices before I build and the selected choice can be used as parameter to the script in the build step.
What would be the way of achieving this? Please help
You can achieve this using Extended Choice Parameters in combination with a properties file.
Create a properties file with content key=value1,value2,value3,..., e.g., key=11,23,45,72,5,16,71,18.
Place this file in your Jenkins master filesystem, e.g., /var/lib/jenkins/userContent/build.properties. You need to write an automation script/create another job to update this file at regular intervals.
In your job configuration, select This project is parameterized > Extended Choice Parameter.
Enter a name for your parameter, e.g., TABLE_VALUE.
Select Basic Parameter Type > Single Select.
Enter the delimiter that you used to separate values in your properties file. In this case, the comma ,.
Select Property File and enter the path to the properties file in Jenkins master - /var/lib/jenkins/userContent/build.properties.
Enter key as the Property Key.
Save the job configuration.
Access the value of the selected parameter using the variable TABLE_VALUE in your pipeline.
Pipeline Code
You can achieve the same in your pipeline by placing this block at the top:
properties([
parameters([
extendedChoice(
name: 'TABLE_VALUE',
description: '',
type: 'PT_SINGLE_SELECT',
multiSelectDelimiter: ',',
propertyFile: '/var/lib/jenkins/userContent/build.properties',
propertyKey: 'key',
quoteValue: false
)
])
])
See the source code for all possible parameters and PT constants for all possible values of type.
Job Configuration
Build Parameters
I have to handle quite a lot of results and store them. I'd like to create something like a tab which I could in the end export as a CSV.
I was using a PSObject with quite a lot of members. I wonder if there is a better way to handle this? If you can show me how to create it and input data it would be nice.
I should create a tab witch look like this:
Site 1 | Tester | result Test 1 | Result test 2 |.... |Result test x
Sitename1 | tester1| Fail | Succes | fail| etc...
Sitename1 | tester1| Succes | Fail | fail| etc...
PS: It has to be working with PowerShell v2.0.
I am new to BDD specflow.
I have to write a scenario wherein after I capture an image, i have to select a value for each defined attribute for that image from a selection list
For Eg:
|Body Part |Location |Group |
| Leg | Left | Skin |
| Hand | Upper | Burn |
| Arm | Right | Ulcer |
I need a way in which i can select a different value for each attribute, every time.
Thanks in advance!
You are looking for Scenario Outline;
Scenario outlines allow us to more concisely express these examples through the use of a template with placeholders, using Scenario Outline, Examples with tables and < > delimited parameters.
Specflow takes each line in the Example table and create from the line a scenario to execute.
I am currently connecting SQL server to robot framework, so i can read my data table name in robot. and I want to use for loop to check table name, somehow, ":FOR" loop keyword cannot found, but I have installed libraries such as operating-system, collections, string, built-in, diff-library and so on. anyone can help me why i cannot use for loop? any help will be appreciated.
The robot framework users guide has a whole section on how to use the for loop. From that section:
The syntax starts with :FOR, where colon is required to separate the
syntax from normal keywords. The next cell contains the loop variable,
the subsequent cell must have IN, and the final cells contain values
over which to iterate. These values can contain variables, including
list variables.
Here's an example from the user's guide, reformatted to use pipes (for clarity):
*** Test Cases ***
| Example 1
| | :FOR | ${animal} | IN | cat | dog
| | | log | ${animal}
| | | log | 2nd keyword
| | Log | Outside loop
Maybe you are not escaping indented cells; as the Tip in the documentation says. Try writing loops like this:
:FOR ${index} IN RANGE ${start} ${stop}
\ log to console index: ${index}
\ Call a Keyword