Unable to execute shell scripts on cygwin(mintty terminal) using Jenkins - windows

Unable to execute shell scripts on Cygwin(mintty terminal) using Jenkins pipeline but I can able to execute same scripts directly on Cygwin(mintty terminal), cygwin is installed on jenkins windows agent, anything I am missing on Jenkins windows agent to configure? and also my shell scripts are not executing on cygwin when using the Jenkins, they are executing on windows command prompt, can someone please advise how to make the jenkins to use the cygwin terminalto execute shell scripts instead of command prompt? .Thank you.
Below is the Jenkins pipeline how I am calling test.sh(test.sh is on jenkins windows agent)
stage('Import') {
steps {
script {
sh "/home/kumar/test.sh"
}
}
}
I see below error when execute the build.
/home/kumar/test.sh
FIND: Invalid switch
mv: cannot stat '/home/kumar/TEST_FILES/*': No such file or directory
below find command used in script.
find /cygdrive/d/Jenkins/workspace/sam-org/testing/app_name/src/abc -name "*.dsx" -exec cp "{}" /home/kumar/ITEST_FILES \

Related

How to echo Jenkins Workspace in Cygwin

I am trying to build a job from jenkins pipeline, my pipeline is calling one shell script which is on windows server, and this script is in cygwin terminal, question is how to use the Jenkins workspace in my shell script in cygwin, tried below commands are not working, can someone please advise. Thanks.
In jenkins Pipeline:
sh "/home/test.sh $WORKSPACE"
In Cygwin:
#!/cygdrive/d/cygwin64/bin/bash --login
WORKSPACE=$1
echo "$WORKSPACE"
Out put from above command is
D:Jenkinsworkspacey_test123_feature_test
but actual workspace is(multibranch pipeline)
Running on win01 in D:\Jenkins\workspace\y_test123_feature_test
Not sure will cygwin take the different command to retrieve the workspace as you can see above output does not contains slashes in between words.
Workspace can be accessed using the enviornmental variable inside the pipeline.
In jenkins Pipeline:
// Get workspace
// This will give you the workspace of the agent that is available in the current stage
def Workspace=env.WORKSPACE
// Convert path with \\ for cygwin
Workspace.replace("\\", "\\\\");
println(Workspace)
sh "/home/test.sh ${Workspace}"

How to execute Linux bash command in Apache NiFi in Windows 10

I use NiFi on Windows 10 machine with installed Linux subsystem (Ubuntu).
My task is to execute bash scripts and commands using NiFi. I tried to use ExecuteProcess and ExecuteStreamCommand with selected commands like simply 'bash' or 'bash ls' for test purposes, but all I got was:
ExecuteProcess[id=4f530725-0171-1000-d1b1-7df587eada7e] /bin/ls:
/bin/ls: cannot execute binary file
If I try to pass basic Windows commands everything is OK.
Is there a way to run bash commands in my case?
I'm not a Windows user but according to the docs, in order to get to the Linux-style commands you have to run Bash.exe, so I'm guessing you'll need to specify -c as an argument followed by the Linux bash command you want to run (as a string), something like:
bash -c "ls"

When using Shell in Windows, how to solve "sh: D:/DevTools/Git/root/restart_all.sh: No such file or directory"?

I've wrote a shell script file on mac to deploy some docker application. But when I copy it to Windows10, it seems that it cannot run properly.
The path after "docker exec xx /foo/bar" is always transferred into an absolute path in windows, and leads to an error like: "sh: D:/DevTools/Git/root/start_zk.sh: No such file or directory".
What's more, when executing "docker exec xx /foo/bar" in powershell or git bash, it can run properly. This problem only occurs when I write it into a file, and run it through "sh deploy.sh".
I've tried to add "\" before "/", but it doesn't help. My code is listed below.
echo "deploying zookeepers..."
docker exec ac sh /root/start_zk.sh
Is there any fault in my script? The command "sh /root/start_zk.sh" after "docker exec" should be a parameter for the docker container to execute, but it seems that it is recognized by windows as a command or path. Is there any way to solve this?

run .sh script via Jenkins to execute aws command error

my problem is that i try to execute shell script to copy created files from msbuild to AWS s3 via Jenkins.
Then i add new build step "Execute Shell" and set to execute shell script by command: sh publishS3.sh nothing happens and files doesn't apper in s3 bucket.
my Jenkins use Local Windows Server.
Then i try to execute the shell script by typing sh publishS3.sh in Jenkins local directory all ok , files was copyed secessfully to s3 bucket , but if i try to do it from jenkins nothing was happen. My publishS3.sh script is:
#!/bin/bash
aws s3 cp Com.VistaDraft.Common.dll s3://download.vistadraft.com/MVP
i was tryed to to check witch output i receive after execute by adding at the end command > output.txt but Jenkins generate an empty file. If i try to do the same locally i was receive an message that i secessfully copyed files to s3. i Set the shell script path of jenkins C:\Program Files\Git\git-bash.exe and using git-bash.exe locally too. Maybe whom know where is a problem ? Please suggest.
You could try to add -ex in the first line of the script to allow you to see what it's doing and ease the debugging:
#!/bin/bash -ex
# rest of script
Make sure the aws tool is in the PATH of the environment where Jenkins runs your script. It might help if you specify full path to the command.
You could put which aws in your script to see what's going on.

how do I get my jmeter test plan to execute in Jenkins on my local windows machine?

I'm trying to get My jmeter test plan to execute in Jenkins. Both jmeter and Jenkins are installed on my local windows machine. I've set up some properties in Jmeter and verified that I can run them from the cmd line successfully with this command: C:\Users\MikeL\Documents\apache-jmeter\bin>jmeter -n -t testApp.jmx -l log.jtl -Jenv=dev -JloopCount=2 Now in Jenkins I've created a new project, create two new parameters and entered the following in "execute shell" based off of exapmples I was able to find on the web.I haven't configured anything else in Jenkins. sh jmeter.sh -n -p user.properties -t C:/Users/MikeL/Documents/apache-jmeter/bin/testApp.jmx -l log.jtl -Jenv=dev -JloopCount=1 suffice to say this script won't build my jmeter test. I recieve this error: Cannot run program "sh" (in directory "C:\Program Files (x86)\Jenkins\workspace\LOS API Regression Tests"): CreateProcess error=2, The system cannot find the file specified
If anybody has any clues I'd be very grateful!
Add this path C:\Users\MikeL\Documents\apache-jmeter\bin to your Environment Variables PATH.
Then Jenkins Build step should be Windows Batch Command
Then the command should be jmeter -n -t testApp.jmx -l log.jtl -Jenv=dev -JloopCount=1
Update:
If you do not want to set the path, just directly give below command as Windows Batch Command.
C:\Users\MikeL\Documents\apache-jmeter\bin\jmeter.bat -n -t C:\Users\MikeL\Documents\apache-jmeter\bin\testApp.jmx -l log.jtl -Jenv=dev -JloopCount=1
Use either Ant/Maven/Gradle to run jmeter tests in the non-gui mode. They can also be integrated with Jenkins
JMeter-Ant
JMeter-Maven
The problem here is cross environment. you need to be running this with windows batch command instead of execute shell. windows wont recognize sh as executable.
C:\Users\MikeL\Documents\apache-jmeter\bin>jmeter -n -t testApp.jmx -l log.jtl -Jenv=dev -JloopCount=2
Run the above in execute windows batch mode

Resources