I have a problem with using jenkins environment variables. I am writing a batch file that can be called when a build is run that will write a file into the build directory with info about how the files were generated. (branch, date time, git revision, etc.)
The batch file just takes in some of the jenkins environment vars via command line parameters, and writes them to a text file. Here is the batch call I make via the Execute Shell step during build:
c:\\temp\\~BuildStamper.bat "$GIT_COMMIT", "$BUILD_URL", "$JOB_NAME", "$BUILD_ID", "$WORKSPACE", "$GIT_BRANCH", "$BUILD_USER"
I have noticed that for arguments that contain white space, an extra comma is being appended inside the quoted delimiters. Sample line from generated text file:
Job Name: "Departure Board Build and Publish,"
I know that it isn't a problem with the processing I am doing inside the batch file, because I can see the values that are passed into the batch file in the job logs Jenkins generates, and the commas exist in the values when they are passed to my batch file.
It almost looks like Jenkins is incorrectly splitting a comma delimited string when it encounters strings with white space, but I couldn't find anything on the net about a problem with Jenkins of that nature.
Anyone else seen this? Am I doing something wrong? I tried passing the vars to Jenkins sans quotes, but then the batch file starts reading each word as a separate argument.
KeepCalmAndCarryOn nailed it, commas are totally extraneous.
Related
In our release pipeline, we have a console app that performs a function which generates an encryption key and outputs it to STDOUT. We need to be able to use this value in a variable during deployment (updating a configuration file with the results from the console app). We've tried using the Output Variables option in the command line task in Azure Devops but unfortunately we need it in a different format... and it just doesn't seem to work as expected.
E.g. Our cmd line tool outputs 908321093RANDOMLYGENERATEDKEY3422543 to STDOUT
The name in our config file for that key is something like Settings.Security.OurKey however the output variable in the command line task does not allow periods (.) and as such is set to SettingsSecurityOurKey... we've also tried SETTINGS_SECURITY_OURKEY, but the variable value is never set by the task.
Is it possible to somehow set the Azure Devops variable to the value of the output variable from the command line or a powershell script? Something like:
set $(Settings.Security.OurKey) = SettingsSecurityOurKey
Or is there a simpler method of achieving this? It seems like it shouldn't be that difficult..
This sounds like a Powershell issue rather than an issue with Azure DevOps.
# Variable name with special characters
$VariableName.That.Contains.Periods # This will NOT work.
${VariableName.That.Contains.Periods} # This will work.
Refer this for more information: https://blog.danskingdom.com/accessing-powershell-variables-with-periods-in-their-name/
If you want a PowerShell variable to contain the standard output from a command, just assign it:
$yourVariableName = your_command_that_writes_to_stdout
If the output is only one line, the PowerShell variable will contain a single string; otherwise it will contain an array.
I am currently trying to create a script that executes a program 100 times, with different parameters, typically pretty simple, but it's adding strange characters into the output filename that is passed into the command call for the program, the script i have written goes as follows
#!/bin/bash
for i in {1..100}
do ./generaterandomizedlist 10 input/input_10_$i.txt
done
I've taken a small screenshot of the output file name here
https://imgur.com/I855Hof
(extra characters are not recognized by chrome so simply pasting the name doesn't work)
It doesn't do this when i manually call the command issued in the script, any ideas?
Your script has some stray CRs in it. Use dos2unix or tr to fix it.
On Ubuntu, inside of a bash script, this ran ( along with some other commands ):
sudo jmeter -n -t test.jmx -l /home/ubuntu/apache-jmeter-2.13/bin/results.jtl
When I do a "ls", I see this file with a question mark in the filename for some reason results.jtl?. I believe this is because there is a new line at the end of the file after the last line of the .jtl:
"
"
That question mark character in the file name is causing me problems. If I open the file with nano, manually delete the newline out of the file and save the file as results.jtl, then I can use the .jtl file like normal.
How can I get JMeter to save the .jtl without adding that newline to the end of the .jtl?
If that is not possible, how can I fix this? I would like to avoid using code to read the file and make adjustments. I would think there should be a more straightforward answer to this.
I also tried to open some of my other scripts involved and remove any white-space or new lines at the end of those scripts. This has not helped either, though. I was thinking about why the "?" would be in the file name, to begin with, and trying any solutions.
Furthermore, if I deleted the "results.jtl?" file and ran the JMeter command on the command line, not inside a bash script file, then JMeter did not save it with the ? in the file name. So, it's only when the bash script is run that the ? is in the file name.
My script writes a file path for uploading a file. I ran the same script in two different ways. It runs properly in the first way, but fails in the second way.
$sPath="C:\ProgramData\Cisco Systems\Screen and Clean\ISB7K_2K\Configuration\op_and_settings_config.bin"
ControlSetText("[TITLE:Open]", "", "[ID:1148]", $sPath)
First way: When I ran the script using the Script Editor; it sent/wrote the proper file path.
Second way: When I called the same script from cmd.exe, it sent/ wrote only the file name (not complete file path). How can I fix this?
In the spirit of Xenobiologist's comment, when you have a quoted string in the command line (your cmd.exe scenario), you need to wrap those in single quotes; the interface can throw a hissy fit (pardon the technical term) if you try to pass a string with single quotes.
Use $sPath='"C:\ProgramData\Cisco Systems\Screen and Clean\ISB7K_2K\Configuration\op_and_settings_config.bin"'
I'm trying to create a shell script via cygwin that will automatically build an executable and run it. It's a very simple format of
#!/bin/bash
gcc test.c -o hello
./hello.exe
When I enter the 2nd and 3rd lines separately, everything works normally. However, if I save those 3 lines into a .sh file, the resulting .exe built has some extra character added in that will always throw off the last line.
helloļ.exe
I can't even replicate the file name because no tool, including the character map/MS word/other ASCII tools online will give me any result. Some online tool gave me the ASCII result , but as far as I can tell that doesn't correspond to anything meaningful. How can I avoid this problem in my shell script?
Very likely you have Windows linefeeds in the .sh file. Make sure you have Unix linefeeds.