Execute echo in windows as maven Dexec.executable - maven

I need to make an echo in windows for the next sentence:
mvn -Dmaven.wagon.http.ssl.insecure=true -q exec:exec -Dexec.executable="cmd /c echo" -Dexec.args='${project.groupId}:${project.artifactId}:'
The problem is that it detects it (-Dexec.executable="cmd /c echo") as multiple commands and returns the following error:
"ERROR] Failed to execute goal
org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (default-cli) on
project openregt: Command execution failed. Cannot run program "cmd \c
echo" (in directory "C:\Users\hlor\Desktop\Test Senel\main"):
CreateProcess error=2, The system cannot find the specified file ->
[Help 1]".
In linux it doesn't give me problems because echo is an executable and with just echo, it works correctly.
PS. Maven version:Apache Maven 3.2.5

Finally I have solved it with the command:
ECHO ON
More info here.
As I need to run it inside a code in Golang, I set the variable through the command:
os.Setenv("ECHO", "ON")

Related

Jenkins job is always failing after windows batch command execution script for rerun cucumber tests

I am running cucumber java tests in jenkins job using maven build as below
After its done in post step under windows batch command execution script I am rerunning failures
mvn clean verify -Dcucumber.options="#rerun.txt --tags #Retry1" -Dthreadcount="2"
After this step every time execution fails. I have read somewhere that if I add any of the below line it should pass but still it fails every time.
echo "exit script"
true
command || true
exit 0
Also added #!/bin/sh at start of script
Please advise.
Since this is supposed to be executed on Windows you may try
mvn clean verify -Dcucumber.options="#rerun.txt --tags #Retry1" -Dthreadcount="2" & echo note: ignoring exit code
or
cmd /c mvn clean verify -Dcucumber.options="#rerun.txt --tags #Retry1" -Dthreadcount="2" & echo note: ignoring exit code
(sorry, don't have Jenkins with Windows agent to test this at hand).

Maven returns unknown lifecycle error when invoked from an sh file

I am running the following command, from a sh file.
echo "This is job" $SLURM_ARRAY_TASK_ID
#! Command line that we want to run:
SLURM_ARRAY_TASK_ID=0
varData='mvn -e clean compile exec:java -Dexec.mainClass=App.Main -Dexec.args="wikiLineSPlits/wiki-004/ wiki-004-'$SLURM_ARRAY_TASK_ID'.txt wiki-004-'$SLURM_ARRAY_TASK_ID' wikiOuts/ wiki-004"'
echo $varData
$varData
Here, running the code results in the following output:
mvn -e clean compile exec:java -Dexec.mainClass=App.Main -Dexec.args="wikiLineSPlits/wiki-004/ wiki-004-0.txt wiki-004-0 wikiOuts/ wiki-004"
Unknown lifecycle phase "wiki-004-0.txt"
But if I copy-paste the output from echo $varData to my terminal screen, then the program executes scuesfully. I am not sure what is the source of error. Any help would be appreciated.
Output from echo $varData:
mvn -e clean compile exec:java -Dexec.mainClass=App.Main -Dexec.args="/home/ak2329/rds/hpc-work/feverDataset/wikiLineSPlits/wiki-004/ wiki-004-0.txt wiki-004-0 /home/ak2329/rds/hpc-work/feverDataset/wikiOuts/ wiki-004"
I would try:
$(echo $varData)
As the last line in your script
The problem is that each stage of your maven command line is being passed the -Dexec arguments, and neither clean nor compile knows what to do with them. If you rewrite your command as to stages
mvn clean compile
and
mvn exec
and only pass the -Dexec args to the second stage, then you should not get those errors.
I finally decided to directly use the shell command, instead of storing it to a variable.
mvn -e clean compile exec:java -Dexec.mainClass=App.Main -Dexec.args="wikiLineSPlits/wiki-004/ wiki-004-'$SLURM_ARRAY_TASK_ID'.txt wiki-004-'$SLURM_ARRAY_TASK_ID' wikiOuts/ wiki-004"
Previously the command used was:
varData='mvn -e clean compile exec:java -Dexec.mainClass=App.Main -Dexec.args="wikiLineSPlits/wiki-004/ wiki-004-'$SLURM_ARRAY_TASK_ID'.txt wiki-004-'$SLURM_ARRAY_TASK_ID' wikiOuts/ wiki-004"'
echo $varData

mvn command is not getting executed in cron

I want to execute maven command (mvn) through a shell script to be executed through cron.
My shell script
echo "setting the variables"
export M2_HOME=/Users/<XXXXX>/Downloads/apache-maven-3.5.2
export M2=/Users/<XXXXX>/Downloads/apache-maven-3.5.2/bin
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre
export PATH=$PATH:/Users/<XXXXX>/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/<XXXXX>/Documents/Software/neo-java-web-sdk-3.54.23/tools:/Users/<XXXXX>/Downloads/apache-maven-3.5.2/bin:/usr/local/go/bin:/Applications/Privileges.app/Contents/Resources:JAVA_HOME/bin
echo "variables set"
{
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/bin/java -version > /Users/<XXXXX>/git/SimpleTests/org.saurav.simpletests/java.log
} || {
echo "java command failed"
}
{
/Users/<XXXXX>/Downloads/apache-maven-3.5.2/bin/mvn -version
} || {
echo "mvn command failed"
}
echo "Tests Executed"
output.log always print
setting the variables
variables set
mvn command failed
Tests Executed
So, it seems the mvn command execution fails.
Output of java command execution has been redirected to java.log but that prints empty. But it seems the java command execution is happening since the fallback echo statement is not printed here.
Best Regards,
Saurav
It seems the mvn file execution is a protected file execution.
With Mac Mojave the programs accessing the protected files have to be given full disk access
Please check here
https://apple.stackexchange.com/questions/378553/crontab-operation-not-permitted
https://support.intego.com/hc/en-us/articles/360016683471-Enable-Full-Disk-Access-in-macOS
After i followed the steps mentioned in the link 1, it started working.
Best Regards,
Saurav

How to execute CMD command on jenkins windows slave using groovy?

I am trying to execute cmd /c echo hello using groovy on a jenkins slave running on windows.
Here is my groovy:
node('WINDOWS-SLAVE-1') {
def cmd_command = "cmd /c echo hello"
cmd_command.execute()
}
And I can see in the job logs that it is indeed running on that windows slave: 'Running on WINDOWS-SLAVE-1'
But I get an error: java.io.IOException: error=2, No such file or directory
And if I try to run linux like ls -l it works fine. Shows me the files of my master.
How can I execute this CMD command on my windows jenkins slave from my groovy script?
If your intention is to execute a command on a given node, you need to use one of the Jenkins Pipeline's steps designed to execute shell scripts (e.g. sh or bat). You need to be aware that any Groovy code in your Jenkinsfile is always executed on the master node:
"1. Except for the steps themselves, all of the Pipeline logic, the Groovy conditionals, loops, etc execute on the master. Whether simple or complex! Even inside a node block!"
Source: https://jenkins.io/blog/2017/02/01/pipeline-scalability-best-practice/#fundamentals
node('WINDOWS-SLAVE-1') {
bat "cmd /c echo hello"
}

Jenkins script execution in console output

When I try to execute the shell script test.sh in Jenkins by adding Execute Shell in Jenkins Build configuration I don't see the shell script output in the jenkins console. I just receive that script has been executed seccessfully , but I don't see the output. My script for example is simple just `
#!/bin/bash +x
echo "hello"
and Jenkins console output is :
Started by user Andrej
Building in workspace C:\Program Files (x86)\Jenkins\workspace\test
[test] $ "C:\Program Files\Git\git-bash.exe" -xe C:\Users\ADMINI~1\AppData\Local\Temp\jenkins6727659055076114908.sh
C:\Program Files (x86)\Jenkins\workspace\test>exit 0
Finished: SUCCESS
How can I configure the jenkins that I can see all the script output and if script have receive error I get unseccessfull build message?
Make sure you set up your windows version of Jenkins to run shell scripts.
I noticed the path for your exe isn't for git or cygwin.
Check out this Stack Overflow answer for how to get windows to run shell commands in Jenkins.

Resources