Mail attachment in jenkins pipeline - jenkins-pipeline

I'm trying to send a mail after my pipe ends that will include some logs that I'm collecting
emailext subject: "${env.JOB_NAME} #" + env.BUILD_NUMBER + " - " + currentBuild.currentResult + " for branch: " + branch_Name + " commit: " + "${git_commit_hash}", body: """
Installation : ${create_cluster_result}
unit test results: ${run_unit_tests_result}
error logs: ${error_logs}
""", attachLog: true, attachmentsPattern: "${error_logs}", to: "$extendedEmailRec"
but I get only one attachment, build.log. What am i missing here?

It seems that "${error_logs}" is the path to only one log file. You can always use wildcards in your pattern as well. For e.g. considering error_logs as your logs directory: (*.log in code below)
""", attachLog: true, attachmentsPattern: "${error_logs}/*.log", to: "$extendedEmailRec"
This way you can end up with as many files with .log extension in your attachments.

Related

Getting error in accessing Jmeter variables (variable_MarchNr) in yaml in beanshell script

I am trying to bulk edit one entity called issues, I call GetIssues API and via json extractor, get all issueId's in variable "issueIds"
json extractor to extract issueIds
Now I want to pass these Ids in other api bulk edit issues, If I directly use these array in next API, I get below error:
{"details":"Unexpected token $ in JSON at position 19","metadata":{}}
So I used to below code in Beanshell Post processor:
var mylist;
props.put("mylist", new ArrayList());
log.info("Detected " + vars.get("issueIds_matchNr") + " issueIds");
for (int i=1; i<= Integer.parseInt(vars.get("issueIds_matchNr")); i++) {
log.info("IDs # " + i + ": " + vars.get("issueIds_" + i));
props.get("mylist").add('"' + vars.get("issueIds_" + i) + '"' );
}
log.info(props.get("mylist").toString());
var issueIdList;
vars.put("issueIdList", props.get("mylist").toString());
log.info(vars.get("issueIdList"));
In my next api call if I pass issueIdList variable, then this works fine in jmeter.
sample variable values in debug sampler are like:
issueIdList=["555bcfc2", "33974d2c", "e58db1d6"]
issueIds_1=555bcfc2
issueIds_2=33974d2c
issueIds_3=e58db1d6
issueIds_matchNr=3
Problem I am facing if I convert my jmx2yaml and tried to run this file with
bzt issues.yml
then while executing above shell script, these issueIds_matchNr, issueIds_3 are not detected, I get below error;
2022-05-29 08:26:10,785 INFO o.a.j.e.J.JSR223PostProcessor: Detected null issueIds
2022-05-29 08:26:10,795 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223PostProcessor
javax.script.ScriptException: Sourced file: eval stream : Method Invocation Integer.parseInt : at Line: 4 : in file: eval stream : Integer .parseInt ( vars .get ( "issueIds_matchNr" ) )
Target exception: java.lang.NumberFormatException: null
in eval stream at line number 4
at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:87) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
My Yaml script is:
- extract-jsonpath:
issueIds:
default: NotFound
jsonpath: $..id
follow-redirects: true
jsr223:
- compile-cache: true
execute: after
language: beanshell
parameters: issueIds
script-file: script.bsh
label: Get Issue Id's
method: GET
url: https://${BASE_URL1}/${PROJECT_ID}/issues?limit=5&sortBy=-displayId&filter%5Bvalid%5D=true
You're missing one important bit: setting the Match Nr in your Taurus YAML
The correct definition of the JSON Extractor would be something like:
extract-jsonpath:
issueIds:
jsonpath: $..id
match-no: -1 #this is what you need to add
Also be informed that starting from JMeter 3.1 it's recommended to use Groovy as the scripting language so consider migrating, it will be as simple as removing the first line from your script.bsh

Unable to write policy file in vault test container

I'm trying to associate a policy file in my vault test container. But It is giving me an error.
Below is the command I'm running.
Container.ExecResult result = vaultContainer.execInContainer("vault", "policy", "write", "admin", "- <<EOF\n" +
"path \"secret/*\" {\n" +
" capabilities = [ \"read\" ]\n" +
"}\n" +
"EOF");
Error:
Container.ExecResult(exitCode=2, stdout=, stderr=Error opening policy file: open - <<EOF
path "secret/*" {
capabilities = [ "read" ]
}
EOF: no such file or directory
)
And policy is not getting written in the vault container. Any help would be greatly apprecited.
I was able to run the command with the following steps:
Create a policy file in the resources folder.
Map this file .withClasspathResourceMapping("policy.hcl", "/opt/policy.hcl", BindMode.READ_ONLY);.
Run the command to create policy. vaultContainer.execInContainer("vault", "policy", "write", "full_access","/opt/policy.hcl")

importfolder errors in latest version of h2o

can someone help with h2o.importfolder error for h2o 3.29 and above ,it works with h2o3.28 and below
dataingest.hex <- h2o.importFolder(path = 's3://h2o_test/', pattern=".*\.snappy\.parquet$")
ERROR: Unexpected HTTP Status code: 412 Precondition Failed (url = http:/xxxxxxxxx:45820/3/ParseSetup) water.exceptions.H2OIllegalArgumentException [1] "water.exceptions.H2OIllegalArgumentException: Column separator mismatch. One file seems to use " " and the other uses "\001"." [2] "
Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page, : ERROR MESSAGE: Column separator mismatch. One file seems to use " " and the other uses " ".

Dredd passing trailing square bracket to API

I'm using Dredd to test an API I have written. It works fine until I try to vary the action uri within a resource. When I have an action of the form
## Retrieve Task [GET /task/{id}]
it sends a request to Drakov with the ] appended. This Drakov server is running the blueprint document.
Drakov 0.1.16 Listening on port 8090
[LOG] GET /task/myid]
[LOG] DELETE /task/myid]
[LOG] GET /task/myid]
You can see this request has an extra ] on the end.
This is my blueprint. It is a subset of the example from the Api Blueprint examples:
FORMAT: 1A
# Advanced Action API
A resource action is – in fact – a state transition. This API example demonstrates an action - state transition - to another resource.
## API Blueprint
# Tasks [/tasks/tasks{?status,priority}]
+ Parameters
+ status `test` (string)
+ priority `1` (number)
## Retrieve Task [GET /task/{id}]
This is a state transition to another resource
+ Parameters
+ id: `myid` (string)
+ Response 200 (application/json)
{
"id": 123,
"name": "Go to gym",
"done": false,
"type": "task"
}
What am I doing wrong?
Your API Blueprint has multiple errors. For instance,
+ Parameters
+ status `test` (string)
+ priority `1` (number)
...should be:
+ Parameters
+ status: `test` (string)
+ priority: `1` (number)
Also, you are defining a resource Tasks with URI Template /tasks/tasks{?status,priority} and then you are trying to define a GET action for the resource with a different URI Template. That is confusing.
I tried to create a sample API Blueprint (saved as sample-blueprint.md) like this:
FORMAT: 1A
# My API
## Task [/task/{id}]
### Retrieve Task [GET]
+ Parameters
+ id: `123` (string)
+ Response 200 (application/json)
{
"id": 123,
"name": "Go to gym",
"done": false,
"type": "task"
}
Then I launched a Drakov server in one terminal like this:
drakov -f *.md
Then I tried to run Dredd:
dredd sample-blueprint.md http://localhost:3000
Everything passed correctly:
$ dredd sample-blueprint.md http://localhost:3000
info: Beginning Dredd testing...
pass: GET /task/123 duration: 42ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 50ms
Is this something you originally wanted to achieve?

How do I create 'draft' items in nanoc?

I'd like to render posts to different folders depending on a status code in the metadata.
For example, if I have an attribute of status: draft I'd like for these items to be rendered to a folder called /draft/, while status: live would be rendered to /blog/. I could then password protect the draft folder so that only I could view it. If there is no status at all it would default to draft.
Is this possible?
In your rules file, use the following:
route '*' do
if item.binary?
item.identifier.chop + '.' + item[:extension]
elsif item[:status]
'/' + item[:status] + item.identifier.chop + '.' + item[:extension]
else
item.identifier + 'index.html'
end
end
This will create a directory for each status you have.
Eg: A source file that begins with
---
title: file1
status: testing
---
will be created in the /testing/ folder.
To remove leftover files after compilation, you can use “nanoc prune” (new in nanoc 3.3.x).

Resources