I am having a simple issue with my Gradle 6.9 custom task.
I am trying to automate some issues in submodules I have, and am starting with a simple task to create a folder in each sub project.
here is what I have so far
task testTask(type:Exec) {
workingDir '.\\service1'
commandLine("cmd", "/c", "mkdir", "1")
workingDir '.\\service2'
commandLine("cmd", "/c", "mkdir", "1")
doLast {
println "some dump message can go here"
}
}
The issue is, the testTask completely ignore service1 command line execution.
I thought that it might be related to working dir, so i tried to have two commandLine in the same workingDir but still, the first will be completely ignored.
I even tried to replace /c with /k which will not terminate the cmd, and it did not work.
Then I had a though about maybe I should use only cmd , /k at the first time am using commandLine, so gradle task will have only one terminal to execute commands ,and the second commandLine can go like mkdir , 1 . Still the same issue.
I can easily have a custom task for each service as a work around the issue, and then finalize all by one task, and then call this task and all the sub task will get executed.
And even easier way, have a batch script to do all the work and call it with my one task.
But I think this is way too messy, And I would love to know why this is behaving like this with only executing the last commandLine.
Related
I have a task created in Windows Task Scheduler which runs a vbs script. I am getting the following error:
It looks like the Task stops looking for the script to run when it finds a space in the path.
However, the path is quoted in the task:
The workaround is to put underscore instead of each space but that would require further workarounds and is not the best way to do it.
How can I set up the task successfully?
I want to run a new cmd window from a batch job in jenkins and then hand over commands one by one to that new cmd.
I know I can start a new cmd and run some commands like this:
start cmd.exe /c "cmd1 & cmd2 & cmd3"
As I have a lot of commands to execute, I'd prefer not to chain them as in the example above, but start a new cmd and then execute each command separately.
Is there a way I can achieve this? I know I could do that by calling a separate batch file with the commands, but some of my coworkers will only have access to jenkins and therefore we need a posibility to have a look into the commands and to change them.
I have created a powershell script which will transfer(using winscp.dll) the files from Jenkins windows server to Linux server. In Jenkins batch command, I have executed that powershell script and it works fine.
But when i tried the same in Jenkins pipeline job, it calls the powershell script and comes to the next step. Its not waiting for powershell script response.
bat 'powershell.exe -ExecutionPolicy Bypass "D:\\Test\\Deploymentscripts\\PowerShellScript\\FileTransfer.ps1 $env:EndMarket $env:Environment"'
I have tried with another powershell script which will connect to Linux server and execute some commands. It works fine in pipeline job
Kindly guide me to fix this issue.
Interesting. Your problem doesn't seem to be in your script because you already explained that it works in a batch job.
I don't know how your pipeline is written, but I would suggest taking a look to Stage, Lock and Milestone which is probably what you need.
The stage step is a primary building block in Pipeline, dividing the
steps of a Pipeline into explicit units and helping to visualize the
progress using the "Stage View" plugin
I guess you could add a stage block like this one in your pipeline:
stage("Previous Step") {
// Some previous step
}
stage("Wait for Script Execution") {
// Call your script
bat 'powershell.exe -ExecutionPolicy Bypass "D:\\Test\\Deploymentscripts\\PowerShellScript\\FileTransfer.ps1 $env:EndMarket $env:Environment"'
}
stage("Next Step") {
// Script already finished its execution
}
But without your pipeline info is just a guessing. Also to improve your script compatibility avoiding "bat and ExcutionPolicy" and using the PowerShell plugin, with that plugin you could simplify your code like this:
powershell -File your_script.ps1
EDIT: I forgot to mention that you can try a different alternative to powershell and the winscp lib using "scp" direct compatibility between Windows and Linux, I'm talking about Cygwin.
With Cygwin installed (with scp) you can use scp as it was a Linux box and a bash script instead powershell:
D:/cygwin-64/bin/run.exe /usr/bin/bash -lic \"/home/user/file.sh\"
In this case I'm running a script silently through Cygwin within a Jenkins Project with a "Run Windows Batch" option. In the script you can add shell commands and the scp instructions you want.
It may seems a little bit more complex but adds more flexibility to perform Windows - Linux tasks.
I've detailed more examples in my blog, you may find it useful.
As avvi mentioned you should check if that variables are being loaded.
You are not calling the script correctly. You are passing in $Env in the powershell invocation which is a powershell variable.
You are in batch mode so should be passing in %.
bat 'powershell.exe -ExecutionPolicy Bypass "D:\\Test\\Deploymentscripts\\PowerShellScript\\FileTransfer.ps1" "%EndMarket%" "%Environment%"'
I am using Jenkins 2.46.1
I have a build pipeline plugin installed and I want to execute a Windows batch file in it. The batch file should execute in a new command window and not on jenkins console output. I give the below Jenkins pipeline groovy script:
node {
stage 'Init'
bat '''
call C:\\myprj\\mybat.bat stop
EXIT /B 0
'''
stage 'Deploy'
bat '''call C:\\myprj\\mybat.bat'''
}
In the init stage, I want to kill the process if it is already open and in stage deploy it should open a new command window and run my batch file.
The problem is that the above does not work. The build is succesful but no command window opens up. Pls suggest
Technically, to do what you're asking you should be able to run
bat 'start cmd.exe /c C:\\myprj\\mybat.bat'
This will launch a new command windows (cmd.exe) and run the batch file given. Depending how your Jenkins slave is running you may not see anything. (eg if it's running as a windows service or different user, you won't see anything)
Alternative solution if the agent is running in a service and you would like to get output:
bat(readFile("mybat.bat"))
Note: The bat file will need to be in your workspace.
Additional Note: You are no longer running the bat file from its original location. Instead it is being run from a temp location created by the underlying durable task system. This means things like %~dp0 in your script are not going to return the paths you might expect.
I have a vbs code that i would like to run via a scheduled task. Say myVBS.vbs; I have created another batch file where called my task as :
cscript.exe //nologon c:\myVBS.vbs
Of course, nothing happened. When i execute myVBS.vbs (via mouse or keyboard, enter command) it works fine.
I am open to any suggestion as to run this task but rather automatically and on timely scheduled. Thank you all for your help.
You might want to try logging the cscript output, to find out what goes wrong:
cscript.exe //Nologo
myVBS.vbs > "%TEMP%output.txt" 2>> "%TEMP%\errors.txt"
Plus mind the typo (//nologo*n*) in your question.