Maven param that contains spaces in jenkins declarative pipeline - java

Let's say that we have a jenkins pipeline that at some point we execute a maven parameterized build:
sh "mvn clean install -DparameterType=${parameter}"
What if the parameter's value contained spaces? Eg the value was "test param".
When running on IDE, this of course works:
mvn clean install -DparameterType="test param"
But if we do sth similar inside the pipeline, like
sh "mvn clean install -DparameterType=\"${parameter}\""
or
sh "mvn clean install -DparameterType=""${parameter}""
it doesn't and the param is passed like
-DparameterType=test param
which is not good for maven. Any ideas please?

You can try using:
sh """
mvn clean install -DparameterType=\"${parameter}\"
"""

Related

configure maven command line args in settings.xml or set in intellij Idea IDEA

I have multiple projects where I have to pass the following parameters each time.
-Djavax.net.ssl.trustStore=C:\VALUE
-P aws-build
-DskipTests=TRUE
The complete command is:
mvn -Djavax.net.ssl.trustStore=C:\VALUE clean install -P aws-build -DskipTests=TRUE
I am trying to configure it permanently so that I won't have to put it each time I do mvn clean install
I am looking to put settings in settings.xml or anywhere in intellij or any working solution is welcome. The objective is if I run mvn clean install, it should pick up those parameters automatically. Thanks!
Got help from a friend:
In Intellij Idea we can do this:
open pom.xml file -> run maven -> new goal -> add the followings in command line:
-Djavax.net.ssl.trustStore=C:\VALUE clean install -P aws-build -DskipTests=TRUE
->OK.

Using mvn clean install from cmd, while running the app from intellij its seems like it rebuilding it

I'm trying to automate some mvn commands to set up the dev env in IntelliJ.
I'm running from cmd:
mvn clean install -DskipTests -P profile1,profile2
When it finish, I'm running the app from IntelliJ, it seems like IntelliJ is compelling and building it again before it runs.
Is there a way to add flags to the cmd command in order to save the step of IntelliJ compiling & building it?

Better way to execute code in a Maven artifact directly? (no project)

I really like the ability to be able to take a Maven artifact that has some useful code in it that can be run directly from the command line. You could run utilities directly from the command line or scripts without first having to download/install anything.
Right now I'm doing it like this inside a script:
mvn -q dependency:copy -Dartifact=${GROUPID}:${ARTIFACTID}:${VERSION}:pom -DoutputDirectory=${TARGET}
mvn -q dependency:copy -Dartifact=${GROUPID}:${ARTIFACTID}:${VERSION} -DoutputDirectory=${TARGET}
mvn -q dependency:copy-dependencies -f ${TARGET}/${ARTIFACTID}-${VERSION}.pom -DoutputDirectory=dependencies
java -cp ${TARGET}/\*:${TARGET}/dependencies/\* ${MAIN}
I tried doing it with the exec plugin, hoping that I could condense that into a single mvn call, but I wasn't able to get it to work.
Is there a better way to do this? (Like in a single mvn call)

Do not print Maven Goals and options command to Console Output in Jenkins

I am passing a secret value using -D in maven Goals and options on jenkins. I don't want to output this secret value to console for security reasons. e.g. maven command in Goals and option on Jenkins look like this:
clean install -DnewSecret=newGeneratedSecret
When the job is run this is printed in console output:
Executing Maven: -B -f /workspace/pom.xml clean install -DnewSecret=newGeneratedSecret
Any idea how to stop printing this? I tried these but didn't work:
clean install -q -DnewSecret=newGeneratedSecret
clean install -DnewSecret=newGeneratedSecret > null
Update: please note the secret value is a generated value which is then set as env variable using EnvInject jenkins plugin.
You could use the Mask Passwords Plugin to define a masked variable for newSecret (e.g., named "SECRET") under Build Environment > Mask Passwords and then use it in your Maven options as an environment variable:
clean install -DnewSecret=${SECRET}
The console would show this:
Executing Maven: -B -f /workspace/pom.xml clean install -DnewSecret=**********

maven - Instruct mvn to find POM upon the path [duplicate]

Supposing my maven project is located in /some/location/project and my current location is /another/location/ how can I run maven build without changing to project location cd /some/location/project?
You can use the parameter -f (or --file) and specify the path to your pom file, e.g. mvn -f /path/to/pom.xml
This runs maven "as if" it were in /path/to for the working directory.
I don't think maven supports this. If you're on Unix, and don't want to leave your current directory, you could use a small shell script, a shell function, or just a sub-shell:
user#host ~/project$ (cd ~/some/location; mvn install)
[ ... mvn build ... ]
user#host ~/project$
As a bash function (which you could add to your ~/.bashrc):
function mvn-there() {
DIR="$1"
shift
(cd $DIR; mvn "$#")
}
user#host ~/project$ mvn-there ~/some/location install)
[ ... mvn build ... ]
user#host ~/project$
I realize this doesn't answer the specific question, but may provide you with what you're after. I'm not familiar with the Windows shell, though you should be able to reach a similar solution there as well.
Regards
For me, works this way: mvn -f /path/to/pom.xml [goals]
You can try this:
pushd ../
maven install [...]
popd
If you want to run maven without this command "mvn -f path/to/pom.xml" you can right click on your folder project (in intellij) and click on Rebuild module "name of your artifactId" (corresponding in your pom.xml). It worked for me.

Categories

Resources