How to pass arguments to mvn spring-boot:run command? - spring-boot

In Command Prompt, how can I pass arguments to mvn spring-boot:run?
For example, I would like to pass in variable environment with the value dev.

Related

Use TeamCity environment variable in shell script

I have a TeamCity environment variable env.TIER_SUFFIX whose value is set as A. I want to be able to use this in my script build step where the script content is
#!/bin/bash
tierSuffix=%env.TIER_SUFFIX%
echo "TierSuffix is [${'$'}tierSuffix]"
export ENV_TIER=%env.DEV_tierSuffix%
The build fails because export ENV_TIER=%env.DEV_tierSuffix% creates env.DEV_ and the build stops. Is there a way to use this in the export command so that it substitutes the value of %env.DEV_A% to ENV_TIER
The way I use TeamCity variables in bash scripts is:
buildCounter="%build.counter%"
where build.counter is TeamCity variable.

Bash script pass arguments to maven

I have a bash script called runMain that is shown below:
#!/bin/bash
mvn exec:java -Dexec.mainClass=org.fjx.main.Main -f fjxRepo/pom.xml -Dexec.args="$#"
So I want to pass the arguments of the bash script to the maven exec. Even though this works when there is only one argument, it does not work for more than one argument e.g. 2 arguments.
Please help me fix this.
If you want to pass the whole argument string and none of the arguments have whitespace in them, you can use $* instead of $#.

Bash script: passing a "string with empty space" onto a command

I have following bash script:
set -o xtrace
TEST_CASE=#Login
mvn clean install --Dcucumber.options="--tags ${TEST_CASE}"
When i run the script the mvn command become:
mvn clean install '-Dcucumber.options=--tags #Login'
Note that the single quote is wrapping the whole -D argument, and the original double quote has disappear. But what i want to see is below:
mvn clean install -Dcucumber.options="--tags #Login"
What is wrong with my original script? how should I update to make it right?
The quotes are not part of the argument; they are there solely to prevent the shell from breaking the string beginning with --D into two arguments to be passed to mvn. The following are all equivalent, creating three arguments:
mvn clean install --Dcucumber.options="--tags ${TEST_CASE}"
mvn clean install "--Dcucumber.options=--tags ${TEST_CASE}"
mvn clean install --Dcucumber.options=--tags" ${TEST_CASE}"
The following creates 4 arguments, since the whitespace between tags and the parameter is not quoted:
mvn clean install --Dcucumber.options=--tags "${TEST_CASE}"
You can quote the space individually in a variety of ways to preserve the 3-argument command. (Remember, adjacent strings are automatically concatenated):
mvn clean install --Dcucumber.options=--tags" ""${TEST_CASE}"
mvn clean install --Dcucumber.options=--tags' '"${TEST_CASE}"
mvn clean install --Dcucumber.options=--tags\ "${TEST_CASE}"
For consistency, set -x always shows a string that would need to be quoted using '...' and quoting the entire string, not just a portion of it.
Is the bash script not working? I'd say use single quotes for literal strings and double quotes for strings that are going to be expanded.
TEST_CASE='#Login'
mvn clean install --Dcucumber.options="--tags ${TEST_CASE}"
What are the error messages?
I think problem is that the quotes aren't actually being included int he cucumber options. So Try this as well:
TEST_CASE='#Login'
CUCE_OPTS='"--tags '${TEST_CASE}'"'
mvn clean install --Dcucumber.options=${CUCE_OPTS}

Cannot access mvn command from bash script

I want to run the following script as:
bash ./scripts/startapp.sh
Here is the script:
#!/bin/bash
str=$HOSTNAME
PREV_IFS=$IFS
IFS=. components=(${str})
ORIGINAL_DIRECTORY=`pwd`
REP_DIRECTORY=$ORIGINAL_DIRECTORY/src/main/resources
for part in "${components[#]}"
do
PATH=$REP_DIRECTORY/"$part"
REP_DIRECTORY=$PATH
done
IFS=$PREV_IFS
CONFIG_PATH=$REP_DIRECTORY/application.yaml
# Below is the final command I want to run from the terminal
`SPRING_CONFIG_LOCATION=$CONFIG_PATH mvn spring-boot:run`
I am getting
mvn: command not found
Without starting the script, I can use mvn spring-boot:run without any problem.
Make sure you have defined:
M2_HOME pointing to the base directory of your Maven installation
PATH must include $M2_HOME/bin
In your script you're overwriting the value of PATH on every iteration. You should change it to:
PATH=$PATH:$REP_DIRECTORY/"$part"

Preserving argument spacing, etc when passing into mvn exec:java

I have a shell script that launches a Maven exec:java process -
exec mvn exec:java -Dexec.mainClass=... -Dexec.args="$*"
Now sadly if I run
./myMagicShellScript arg1 "arg 2"
the single string arg 2 doesn't make it through as a single argument as I'd like.
Any thoughts as to how to escape / pass things through properly (perferably in a clean way)?
I took a look at the mvn script and did some testing. This is what I came up with:
Try changing your script to look like this:
args=(${#// /\\ })
exec mvn exec:java -Dexec.mainClass=... -Dexec.args="${args[*]}"
That changes all spaces which are within each array element to be escaped with a backslash.

Resources