Setting Jenkins build name from package.json version value - json

I want to include the value of the "version" parameter in package.json as part of the Jenkins build name.
I'm using the Jenkins Build Name Setter plugin - https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin
So far I've tried to use PROPFILE syntax in the "Build name macro template" step:
${PROPFILE,file="./mainline/projectDirectory/package.json",property="\"version\""}
This successfully creates a build, but includes the quotes and comma surrounding the value of the version property in package.json, for example:
"0.0.1",
I want just the value inside returned, so it reads
0.0.1
How can I do this? Is there a different plugin that would work better for parsing package.json and getting it into the template, or should I resort to some sort of regex for removing the characters I don't want?
UPDATE:
I tried using token transforms based on reading the Token Macro Plugin documentation, but it's not working:
${PROPFILE%\"\,#\",file="./mainline/projectDirectory/package.json",property="\"version\""}
still just returns
However, using only one escaped character and only one of # or % works. No other combinations I tried work.
${PROPFILE%\,,file="./mainline/projectDirectory/package.json",property="\"version\""}
which returns "0.0.1" (comma removed)
${PROPFILE#\"%\"\,,file="./mainline/projectDirectory/package.json",property="\"version\""}
which returns "0.0.1", (no characters removed)
UPDATE:
Tried to use the new Jenkins Token Macro plugin's JSON macro with no luck.
Jenkins Build Name Setter set to update the build name with Macro:
${JSON,file="./mainline/pathToFiles/package.json",path="version"}-${P4_CHANGELIST}
Jenkins build logs for this job show:
10:57:55 Evaluated macro: 'Error processing tokens: Error while parsing action 'Text/ZeroOrMore/FirstOf/Token/DelimitedToken/DelimitedToken_Action3' at input position (line 1, pos 74):
10:57:55 ${JSON,file="./mainline/pathToFiles/package.json",path="version"}-334319
10:57:55 ^
10:57:55
10:57:55 java.io.IOException: Unable to serialize org.jenkinsci.plugins.tokenmacro.impl.JsonFileMacro$ReadJSON#2707de37'

I implemented a new macro JSON, which takes a file and a path (which is the key hierarchy in the JSON for the value you want) in token-macro-2.1. You can only use a single transform per macro usage.

Try the token transformations # and % (see Token-Makro-Plugin):
${PROPFILE#"%",file="./mainline/projectDirectory/package.json",property="\"version\""}

(This will only help if you are using pipelines. But for what it's worth,..)
What works for me is a combination of readJSON from the Pipeline Utility Steps plugin and directly setting currentBuild.displayName, thusly:
script {
// readJSON from "Pipeline Utility Steps"
def packageJson = readJSON file: 'package.json'
def version = packageJson.version
echo "Setting build version: ${packageJson.version}"
currentBuild.displayName = env.BUILD_NUMBER + " - " + packageJson.version
// currentBuild.description = "other cool stuff"
}
Omitting error handling etc obvs.

Related

Fastlane passed parameters from CLI are trimmed

I am trying to pass the Pull request title as a parameter to the lane
I run this command for example
fastlane android distribute release_notes:$PR_TITLE
And I can see from the logs that the command is executed correctly with the complete title
[16:37:52]: $ bundle exec fastlane android distribute release_notes:ref: copy the services module inside app module
but when I print the passed argument I found it trimmed
desc "distribute new build for testers, set internal to true to pass it for internal testrs"
lane :distribute do |options|
print "\n"
print "release_notes"
print options[:release_notes]
which prints release_notes ref:, trimmed after the : and it even gets trimmed after newlines in a strange way
As you can see from your release_notes:string command, fastlane parses colons in a key/value format. So it will break if you pass in a string which includes a colon.
A more common pattern is to read the release notes from the environment variable within your lane. So instead of using options at all just do something like
notes = ENV['PR_TITLE']

How to load a csv file with header and data type in neo4j?

Am I correct that one cannot use cypher to load a csv file with header together with datatype?
(By "with datatype", I mean header with something like this:
For entities:
orderId:ID(Order) customerId:IGNORE
For relationships:
:START_ID(Order) :END_ID(Product)
)
According to this two websites: https://neo4j.com/developer/guide-import-csv/, http://jexp.de/blog/2015/04/how-to-neo4j-data-import-minimal-example/
It seems that I could import data together with header in this way in either powershell or command prompt (I am using a windows computer):
path\to\neo4j-community-3.1.1\bin\neo4j-import --into graph.db \
--nodes:Person C:\SavedNewest\people_header.csv, C:\SavedNewest\people.csv \
--relationships:KNOWS C:\SavedNewest\friendships_header.csv,C:\SavedNewest\friendships.csv
(The csv are reconstructed according to this website: http://jexp.de/blog/2015/04/how-to-neo4j-data-import-minimal-example/)
Error from PowerShell:
At line:2 char:3
+ --nodes:Person C:\SavedNewest\people_header.csv,https://gist.githubus ...
+ ~
Missing expression after unary operator '--'.
At line:2 char:3
+ --nodes:Person C:\SavedNewest\people_header.csv,https://gist.githubus ...
+ ~~~~~~~~~~~~
Unexpected token 'nodes:Person' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator
Error from Command prompt:
WARNING: This command does not appear to be running with administrative rights.
Some commands may fail e.g. Start/Stop
WARNING: neo4j-import is deprecated and support for it will be removed in a future
version of Neo4j; please use neo4j-admin import instead.
Input error: Expected '--relationships' to have at least 1 valid item, but had 0 []
Caused by:Expected '--relationships' to have at least 1 valid item, but had 0 []
java.lang.IllegalArgumentException: Expected '--relationships' to have at least 1 valid item, but had 0 []
at org.neo4j.kernel.impl.util.Validators.lambda$atLeast$6(Validators.java:125)
at org.neo4j.helpers.Args.validated(Args.java:640)
at org.neo4j.helpers.Args.interpretOptionsWithMetadata(Args.java:608)
at org.neo4j.tooling.ImportTool.extractInputFiles(ImportTool.java:508)
at org.neo4j.tooling.ImportTool.main(ImportTool.java:389)
at org.neo4j.tooling.ImportTool.main(ImportTool.java:334)
What is the cause of error and how should I load a csv file with header and data type correctly?
Edit:
New Input for cmd:
C:\Users\tsutomu\Desktop\MSS\Bachelorarbeit\neo4j-community-3.1.1\bin\neo4j-import --into graph.db --nodes:Person "file:c:/SavedNewest/people_header.csv,file:c:/SavedNewest/people.csv" --relationships:KNOWS "file:c:/SavedNewest/friendships_header.csv,file:c:/SavedNewest/friendships.csv"
The Error:
Input error: Directory of file:c:\SavedNewest\people_header.csv doesn't exist
Caused by:Directory of file:c:\SavedNewest\people_header.csv doesn't exist
java.lang.IllegalArgumentException: Directory of file:c:\SavedNewest\people_header.csv doesn't exist
at org.neo4j.kernel.impl.util.Validators.matchingFiles(Validators.java:48)
at org.neo4j.kernel.impl.util.Converters.lambda$regexFiles$7(Converters.java:76)
at org.neo4j.kernel.impl.util.Converters.lambda$toFiles$8(Converters.java:95)
at org.neo4j.helpers.Args.interpretOptionsWithMetadata(Args.java:608)
at org.neo4j.tooling.ImportTool.extractInputFiles(ImportTool.java:508)
at org.neo4j.tooling.ImportTool.main(ImportTool.java:388)
at org.neo4j.tooling.ImportTool.main(ImportTool.java:334)
Same error for powershell.
The path of people_header.csv: C:\SavedNewest\people_header.csv
Is there anything I should add to environmental path?
You have a couple of issues in your command line:
You cannot have embedded spaces in your command line arguments. For example, C:\SavedNewest\people_header.csv, C:\SavedNewest\people.csv should be a single argument, so you need to either remove the space after the comma or double-quote the entire argument.
The file path URLs must be formatted appropriately. To quote from the developer guide:
Make sure to use the right URLs esp. file URLs.+ On OSX and Unix use
file:///path/to/data.csv, on Windows, please use
file:c:/path/to/data.csv

ElectronJs: What does curly braces '{}' mean in package json

I was going through some electron package.json examples where I found some interpolations like given below:
"updater": {
"urls": {
"darwin": "{{& SQUIRREL_UPDATES_URL }}/update/%CHANNEL%/darwin?version=%CURRENT_VERSION%",
"win32": "{{& SQUIRREL_UPDATES_URL }}/update/%CHANNEL%/win32",
"linux": "{{& SQUIRREL_UPDATES_URL }}/update/%CHANNEL%/linux"
}
}
"piwik": {
"serverUrl": "{{& PIWIK_SERVER_URL }}"
},
"sentry": {
"dsn": "{{& SENTRY_DSN_PRIVATE }}"
}
I do not really know the following:
what does this {{}} mean in json
where does these variable exist
what does & mean in {{}} "{{& SENTRY_DSN_PRIVATE }}"
If anyone can explain then it would be really kind. Many thank in advance.
I guess you are talking about Whatsie and it's package.json.
If you take a look at one of the Gulp tasks located in the file tasks/compile.coffee, you'll be able to see the lines (in CoffeeScript):
# Move package.json
gulp.task 'compile:' + dist + ':package', ['clean:build:' + dist], ->
gulp.src './src/package.json'
.pipe mustache process.env
.pipe gulp.dest dir
Here the actual package.json is being passed to a mustache template engine - it receives a template as a first argument (package.json here acts like a template) and a data to be inserted in the template as a second argument - process.env.
As package.json acts like a template for mustache, you can use mustache syntax in it.
Curly braces {{}} are the part of it, they are used as placeholders which will be replaced by the actual data, when templates are being compiled. In the mustache docs you can also find a line:
You can also use & to unescape a variable: {{& name}}
So {{& name}} is to prevent values from being escaped. Otherwise, if you don't use & and values for output have some dangerous characters , they will be replaced by more secure ones (originally to prevent XSS in templates), as a result it will transform initial value, which is not always what you want. In this case author wants to preserve original value.
Going back to process.env - it is an object which gives access to environment variables in Node.JS. There is a file in repository .env-example with an example of env variables developer has to set in order to have the application work differently in different environments (for example on local machine or CI server). Names of some of the variables in this file are the ones that are used in a package.json as template placeholders - I guess author of the app uses all of this to simplify a build process for different environments.

How to create a iso file by grub-mkrescue and assign its label?

I'm trying to create a iso bootable file by grub-mkrescue. But I require to assign the iso's label.
After read the man page, I guess here is a correct command line, but failed.
grub-mkrescue -o "my_arch.iso" -- -volid=MY_ARCH my_iso_dir
It will show error as:
xorriso 1.4.2 : RockRidge filesystem manipulator, libburnia project.
Drive current: -outdev 'stdio:my_arch.iso'
Media current: stdio file, overwriteable
Media status : is blank
Media summary: 0 sessions, 0 data blocks, 0 data, 19.1g free
Added to ISO image: directory '/'='/tmp/grub.ZoYEzy'
xorriso : UPDATE : 613 files added in 1 seconds
xorriso : FAILURE : -as mkisofs: Unrecognized option '-volid=MY_ARCH'
xorriso : UPDATE : 613 files added in 1 seconds
xorriso : aborting : -abort_on 'FAILURE' encountered 'FAILURE'
According the 'info grub-mkrescue' document:
All arguments not explicitly listed as 'grub-mkrescue' options are
passed on directly to 'xorriso' in 'mkisofs' emulation mode. Options
passed to 'xorriso' will normally be interpreted as 'mkisofs' options;
if the option '--' is used, then anything after that will be interpreted
as native 'xorriso' options.
Non-option arguments specify additional source directories. This is
commonly used to add extra files to the image:
The -as mkisofs emulation of xorriso understands
-V MY_ARCH
or
-volid MY_ARCH
but not
-volid=MY_ARCH
Further be aware that you obviously use the intermediate C version of
grub-mkrescue which does not comply to the documentation you quoted.
This version demands '--' as delimiter between grub-mkrescue options
and xorriso -as mkisofs options.
But if you have '--' among the arguments of old grub-mkrescue shell script
or of current grub-mkrescue C program, then you will drop out of mkisofs
emulation. This will earn you an error message
xorriso : FAILURE : Not a known command: 'my_iso_dir'

Ways to parse JSON using KornShell

I have a working code for parsing a JSON output using KornShell by treating it as a string of characters. The issue I have is that the vendor keeps changing the position of the field that I am intersted in. I understand in JSON, we can parse it by key-value pairs.
Is there something out there that can do this? I am intersted in a specific field and I would like to use it to run the checks on the status of another RESTAPI call.
My sample json output is like this:
JSONDATA value :
{
"status": "success",
"job-execution-id": 396805,
"job-execution-user": "flexapp",
"job-execution-trigger": "RESTAPI"
}
I would need the job-execution-id value to monitor this job through the rest of the script.
I am using the following command to parse it:
RUNJOB=$(print ${DATA} |cut -f3 -d':'|cut -f1 -d','| tr -d [:blank:]) >> ${LOGDIR}/${LOGFILE}
The problem with this is, it is field delimited by :. The field position has been known to be changed by the vendors during releases.
So I am trying to see if I can use a utility out there that would always give me the key-value pair of "job-execution-id": 396805, no matter where it is in the json output.
I started looking at jsawk, and it requires the js interpreter to be installed on our machines which I don't want. Any hint on how to go about finding which RPM that I need to solve it?
I am using RHEL5.5.
Any help is greatly appreciated.
The ast-open project has libdss (and a dss wrapper) which supposedly could be used with ksh. Documentation is sparse and is limited to a few messages on the ast-user mailing list.
The regression tests for libdss contain some json and xml examples.
I'll try to find more info.
Python is included by default with CentOS so one thing you could do is pass your JSON string to a Python script and use Python's JSON parser. You can then grab the value written out by the script. An example you could modify to meet your needs is below.
Note that by specifying other dictionary keys in the Python script you can get any of the values you need without having to worry about the order changing.
Python script:
#get_job_execution_id.py
# The try/except is because you'll probably have Python 2.4 on CentOS 5.5,
# and the straight "import json" statement won't work unless you have Python 2.6+.
try:
import json
except:
import simplejson as json
import sys
json_data = sys.argv[1]
data = json.loads(json_data)
job_execution_id = data['job-execution-id']
sys.stdout.write(str(job_execution_id))
Kornshell script that executes it:
#get_job_execution_id.sh
#!/bin/ksh
JSON_DATA='{"status":"success","job-execution-id":396805,"job-execution-user":"flexapp","job-execution-trigger":"RESTAPI"}'
EXECUTION_ID=`python get_execution_id.py "$JSON_DATA"`
echo $EXECUTION_ID