Are backslashes supported in Groovy comments? - jenkins

I experienced a weird Jenkins error while trying to run a groovy-scripted pipeline that contained backslashes inside comments.
Here is the offending code:
// The script below depends on:
// * The presence of a recent nuget.exe in c:\tools (v5.7)
// * The presence of the xxx plugin installed for user foo\username
I'm aware the backslash is used in many languages to start an escape sequence, but I had never before experienced backslashes being an issue inside comments.
I wonder if this backslash in comments behavior is due to Groovy itself or rather a bug in the way Jenkins interprets it...
Edit: I solved my issue by replacing the offending \ with \\ but then noticed I had forgotten to double the backslash in c:\tools, and still Jenkins did not complain. It seems Jenkins (or Groovy) tried to interpret the \u in foo\username as introducing an hex character code... but was okay with \t for it probably was interpreted as a tab!

Related

Jenkins: Remove Whitespace from ${ITEM_FULL_NAME}

I have a Jenkins server built on a Windows PC, when it builds my project it adds the word Pipeline with a space character separator to the project in the workspace. The value ${ITEM_FULL_NAME} is safe from an OS point of view but I have a problem with a process (Xilinx Memory Interface Generator) that runs in the pipeline that cannot cope with spaces in the path (it is bad that that process cannot cope with space characters in directories but I am stuck with it). Is there a way to ensure the generated ${ITEM_FULL_NAME} variable does not contain space characters?
I have tried to work around the issue by creating a Power Shell script to rename the directory using the underscore character but as feared I cannot do this as a process is running on the folder.
I have looked at the Whitespace plugin but I think this is for inputs into the pipeline not for what Jenkins generates.
I also looked at Restrict Project Naming but again think this is for project input and not what is generated by Jenkins.
Any suggests gratefully received; I am new to Jenkins so if you have a solution it might need spelling out, thank you.
You can use trim to remove the white spaces:
ITEM_FULL_NAME= ITEM_FULL_NAME.trim()
Another way :
If the variable is a parameter variable then you can use below:
parameters { string(defaultValue: "", description: '', name: 'ITEM_FULL_NAME', trim: true) }

Revit Ironpython Shell - Parsing a list of filenames with a number after a backslash in the path

I want to read in a list of files (inc path) from either a spreadsheet or a text file for some downstream processing. The list has been generated as a log from another process and the path includes a 2 digit year folder followed by a project number folder as follows:
\\servername\projects\19\1901001\project files\filetobeprocessed.abc
The problem is as soon as the above string is read in, it is interpreted as
\\servername\\projects\x019\x01901001\\project files\x0ciletobeprocessed.abc
Which then means that I cannot use the path to access the file.
Assigning the path string to a variable, I have tried:
thePath = repr(pathreadfromfile)
After assigning the path string I have tried fixing the string using
thePath.replace('\x0','\\')
thePath.replace('\\x0','\\')
thePath.replace(r'\x0','\\')
Nothing seems to fix the path so that it can be used to open the file.
I can't find anything in either python or Ironpython that suggests a fix for this programatically. I know that you can fix this is the path is known within the code by using r'' to use raw text to create the path.
Any help appreciated
Obviously, the backslash \ is interpreted as an escape character.
For a really simple solution, hopefully the simplest, I would suggest using forward slash / for all your path separators instead of backslash.
If you really need the backslash somewhere further down the road, you can replace them back again.

How can I get parens in a URL using the Doxia APT format?

I am using the APT format to create documentation on a maven project. I am trying to link to a JavaDoc method description, which URL contains a parentheses.
For example, the url
http://myjavadoc/methodname(java.lang.string)
Becomes
http://myjavadoc/methodnamejava.lang.string
Trying to use URL-encoding produces a similar result in that the percent symbol is stripped out.
http://myjavadoc/methodname28java.lang.string29
In both cases, escaping the character with a backslash has no effect.
Does anyone know how to get parens (or percents) to be interpreted through apt correctly?
You should mention your doxia version.
Anyway both methods worked for me with doxia 1.6
Link to {{{http://myjavadoc/methodname(java.lang.string)}http://myjavadoc/methodname(java.lang.string)}}.
Link to {{http://myjavadoc/methodname(java.lang.string)}}.

How to specify $* in a parameter for a Jenkins job?

I have a Jenkins job that has a test.excludes parameter that I would like to default to **/*$* (ie exclude all inner classes). Normally I would specify this value in a file, but in this case, I don't want to submit any files since this is investigative work (as I see tests that are failing, I will add them to test.excludes).
The problem is that the $* in **/*$* is being expanded to the command line variables. Using **/*$$* only changes the problem to $$ being expanded to the pid. Escaping * using \ doesn't work (inner classes are still run). Escaping by wrapping the entire value in ' does nothing to prevent the $* from being replaced.
Is there a way to get the behavior I want?
The following really ugly expression works: $(echo '**/*$*').

Why won't applications in Program Files run using os.execute in lua?

I'm trying to run an executable using Lua's os.execute() function. If I do something like the following it does not work:
os.execute("C:\\\Program Files\\\Movie Maker\\\moviemk.exe")
However, if I put my lua file in the same path that moviemk.exe is in then it can call it.
Any ideas why this may be?
P.S. I'm using Windows XP SP3
This is a classic problem with the command shell. It isn't really a Windows specific problem, except that on *nix, people never really got into the habit of putting spaces in file names, and Windows puts spaces in several default system places such as C:\Program Files.
What is happening is that os.execute(str) is implemented in terms of the ANSI C function system(str), which on Windows tries to duplicate the effect of typing "cmd /C "..str to the command prompt. (On *nix, it uses /bin/sh -c instead of cmd /C.)
The classic problem is that this has to split the complete command string at whitespace to decide what program to run, and what its arguments are.
Your original example: os.execute("C:\\Program Files\\Movie Maker\\moviemk.exe") effectively became cmd /c c:\program files\movie maker\moviemk.exe, which after splitting it up on whitespace, CMD tried to find a program named c:\program to execute with arguments named files\movie and maker\moviemk.exe. This isn't what you intended.
The solution is to be much more defensive about quoting.
I would write this as:
os.execute [["C:\Program Files\Movie Maker\Moviemk.exe"]]
If there were additional command line arguments to be supplied, I would use double-quotes around each, and a single space between arguments. Using the long string syntax [[...]] has the advantage that backslash isn't a special character, so you don't need extra leaning toothpicks making it harder to read the string literal.
Using double quotes around each argument should work on both Windows and *nix, although it is harder to find commands that are the same on both platforms, of course.
One other detail to be aware of is that \Programs Files might not be on C:. There might not even be a disk named C:. (My work PC boots from E: and I find more buggy programs that way.) The easiest way to learn the correct pathname is to just use the environment variable ProgramFiles. There are many other ways.
Try:
os.execute("C:\\Program Files\\Movie Maker\\moviemk.exe")
or:
os.execute("C:/Program Files/Movie Maker/moviemk.exe")
The '\' character is used for escape characters in Lua.

Resources