build Jenkins use properties from file - string

I want to use the option "This build has the parameters" in Jenkins ( hudson ) and then instead of String parameters, I want to load these settings from an external file that contains all the parameters (val=value ...) .
I find this plugin in the "Trigger parameterized" that puts a file paraetres but after a build, me I need this file in the first build
thank you

I would suggest that you specify the path to the file as a String parameter, call it PARAMS_FILE
The file should look like.
VAR1=someValue
VAR2=someOtherValue
If you use bash in your build steps then you could do.
. ${PARAMS_FILE}
At the beginning of an execute shell and the params would be set for that shell.
That would solve the problem for using shell build steps atleast.
If you use other build steps you would have to do another solution.

Related

How to edit and save Python file via command-line

I have a Dockerfile that in one of its RUN instructions creates a conan file. I'd like to edit and save that conan file in my Dockerfile to set project specific settings. Is there a way to do so via command line, for example the Python prompt?
Alternatively is there a way to embed a Python file in a Dockerfile?
I don't know any command to do so. But I would suggest you to use another approach :
Create a Conan template file with environment variables as placeholders (youconanfile.dist).
use envsubst command in order to runtime-create the file you need with current project variables.
I use this technique in a Docker stack to generate multiple files (wp-cli.yml, deploy.php...). My example is in a Makefile. If you need to use it in your Dockerfile, it is possible assuming that
envsubst is installed on your container
COPY command is used for pushing the Conan template file in your container.

Calling groovy execute cross platform

I am currently using gmaven plus to run a groovy command inside maven.
The command (for the sake of example) would be
git help
If I run it on linux I can do:
'git help'.execute().text.trim()
This however doesn't work on windows. Instead I need to do:
'cmd /C git help'.execute().text.trim()
Is there a cross platform way of doing this?
Seeing that it worked for others got me thinking and indeed the problem was with my own PATH configuration;
Apparently, if you define git in the path as follows:
"C:\Program Files (x86)\Git\bin"
then when running from command it will find git. However, groovy will NOT find it.
On the other hand, if you define git in the path as follows:
C:\Program Files (x86)\Git\bin
i.e. without the "". Then everything works fine.
see also https://serverfault.com/questions/349179/path-variable-and-quotation-marks-windows

Jenkins pipeline/groovy: Load script relative to current script

I have a pipeline groovy script, which I load from a different script:
load("path/to/my/script/pipeline.groovy")
Now, in this script, I want to load another groovy script. But I do not know the full path/to/my/script path. I tried:
load("./subfolder/subscript.groovy")
But it cannot find it this way. Can I somehow load a groovy script relative to the current script file?
You may want to consider using the shared library plugin if you are loading multiple remote scripts.
If the groovy file exists in a subfolder, you can use the findFiles step:
def subscript = findFiles(glob: '**/subscript.groovy')
load(subscript[0].path)
One way would be to load the 2nd script (curl) in your working directory, from there the 1st script can find and load it.

CMake: How to execute a command before make install?

This is the way I install the config files:
file(GLOB ConfigFiles ${CMAKE_CURRENT_SOURCE_DIR}/configs/*.xml
${CMAKE_CURRENT_SOURCE_DIR}/configs/*.xsd
${CMAKE_CURRENT_SOURCE_DIR}/configs/*.conf)
install(FILES ${ConfigFiles} DESTINATION ${INSTDIR})
But I need to convert one of the xml files before installing it. There is an executable that can do this job for me:
./Convertor a.xml a-converted.xml
How can I automatically convert the xml file before installing it? It should be a custom command or target that installing depends on it, I just don't know how to make the install command depend on it though. Any advice would be appreciated!
Take a look at the SCRIPT version of install:
The SCRIPT and CODE signature:
install([[SCRIPT <file>] [CODE <code>]] [...])
The SCRIPT form will invoke the given CMake script files during
installation. If the script file name is a relative path it will be
interpreted with respect to the current source directory. The CODE
form will invoke the given CMake code during installation. Code is
specified as a single argument inside a double-quoted string.
For example:
install(CODE "execute_process(\"./Convertor a.xml a-converted.xml\")")
install(FILES a-converted.xml DESTINATION ${INSTDIR})
Be sure to checkout the entry for execute_process in the manual. Also be aware that macro expansion inside the CODE parameter can be a bit tricky to get right. Check the generated cmake_install.cmake in your build directory where the generated code will be placed.
I think that your specific case would work better if you were to use a custom command and target like so:
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/a-converted.xml
COMMAND ./Convertor a.xml a-converted.xml
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Convertor
)
add_custom_target(run ALL
DEPENDS ${CMAKE_BINARY_DIR}/a-converted.xml
COMMENT "Generating a-converted.xml" VERBATIM
)
install(
FILES ${CMAKE_BINARY_DIR}/a-converted.xml
DESTINATION ${INSTDIR}
)
Note: I don't have all the details, so the directories are probably
not exactly what you'd want in your environment, although it's
a good idea to generate files in the ${CMAKE_BINARY_DIR} area.
That way you can be sure that the file a-converted.xml is built at the time you want to install it. Especially, these two rules make sure that if you make changes to the file, it gets recompiled.

Running .jar File on Linux

I have a .jar file that reads two files from within its current folder and produces as output a .txt file and a separate folder with multiple other .txt files. This works perfectly in Windows using this code to create the directory:
static String dir = System.getProperty("user.dir");
I used the instructions here: https://askubuntu.com/questions/192914/how-run-a-jar-file-with-a-double-click to set up my .jar file to run on a simple double-click, but as of right now, it does nothing when double-clicked. My guess is that the above line of code does not translate well to Linux. Anybody know how to resolve this?
First, try running it on the command-line, with
java -jar <file.jar>
The user.dir property is cross-platform (see here) so it should not be the problem. However, are you using correct file separators? Remember it's '/' on UNIX and '\' on Windows.
Try java -jar Jarname.jar and pass other files as arguments after this command
The code line you gave works fine on linux.
My best guess is that you're then trying to use this directory path by adding a windows-specific path separator (like path + "\subdir") which isn't appropriate for linux (you should build a new File object instead).
Either that, or your jar file isn't being executed at all. Have you tried doing something very simple in your jar file to see if anything is being run? Have you tried running your jar with java -jar myapp.jar to see if any exceptions are thrown or error messages displayed?
You will need to manually tweak your build process to get the jar file marked as executable. In your build xml file, there is a target, "-post-jar", that is called after the jar is built. You'll need to make that target and use Ant's chmod task to modify your jar. Once you do that it will occur every time you make a jar file in that project.
It will run fine as long as you have a JRE installed.
Read this article to know more.

Resources