Execute external powershell script in jenkins pipleline - powershell

I was trying to execute powershell script in a remote machine via jenkins pipeline.my script location ex: $server_vm_name\d$\scripts\testscript.ps1 . and I need to pass parameter to the testscript.ps1 as parameter name -clientpath. for the client path u have used this external path ex:
\${client_vm_name}\d$\Client\Application . I have used the network paths for both script location and parameter
I have write the following code snippet to get the work done. but its not working. anyone have idea what i have done in wrong way?.
error msg :
*
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 885: unexpected char: '\' # line 885, column 49.
rshell script: "\\$db_vm_name\d$\script
stage('Installation') {
agent{
label PS_AGENT_LABEL
}
steps{
script{
powershell script: "\\$server_vm_name\d$\scripts\testscript.ps1 -clientPath \\${client_vm_name}\d$\Client\Application"
}
}
}

Related

Getting a "Missing token: ASSIGN" error when running OpenModelica script through a batch file

I am trying to run an OpenModelica script using a DOS .bat file. But facing some issues.
The batch file runmodelica.bat has
%OPENMODELICAHOME%\bin\omc testscript.mos
The file testscript.mos is
loadModel(Modelica)
getErrorString()
loadFile("HelloWorld.mo")
simulate(HelloWorld)
getErrorString()
If I run the commands in the testscript.mos file from an OM Shell by changing to that directory, everything works fine. But If I run the batch file from the DOS prompt, I get the following error
Error processing file: testscript.mos
[C:/Users/blahblah/testscript.mos:2:1-2:1:writable] Error: Missing token: ASSIGN
# Error encountered! Exiting...
# Please check the error message and the flags.
Execution failed!
The HelloWorld.mo file comes with the standard installation and I haven't modified it
class HelloWorld
Real x(start = 1);
parameter Real a = 1;
equation
der(x) = - a * x;
end HelloWorld;
I am new to OpenModelica and searched online but couldn't find a solution. Any help is appreciated.
All the commands run in the OM Shell but not when invoked from the bat file.
The script code needs to be valid Modelica, so you need ; after each command.
loadModel(Modelica);
getErrorString();
loadFile("HelloWorld.mo");
simulate(HelloWorld);
getErrorString();

SCP command not working in karate project - it throws command error:cannot run program scp.exe: CreateProcess error=2 [duplicate]

I'm trying to execute bash script using karate. I'm able to execute the script from karate-config.js and also from .feature file. I'm also able to pass the arguments to the script.
The problem is, that if the script fails (exits with something else than 0) the test execution continues and finishes as succesfull.
I found out that when the script echo-es something then i can access it as a result of the script so I could possibly echo the exit value and do assertion on it (in some re-usable feature), but this seems like a workaround rather than a valid clean solution. Is there some clean way of accessing the exit code without echo-ing it? Am I missing on something?
script
#!/bin/bash
#possible solution
#echo 3
exit 3;
karate-config.js
var result = karate.exec('script.sh arg1')
feture file
def result = karate.exec('script.sh arg1')
Great timing. We very recently did some work for CLI testing which I am sure you can use effectively. Here is a thread on Twitter: https://twitter.com/maxandersen/status/1276431309276151814
And we have just released version 0.9.6.RC4 and new we have a new karate.fork() option that returns an instance of Command on which you can call exitCode
Here's an example:
* def proc = karate.fork('script.sh arg1')
* proc.waitSync()
* match proc.exitCode == 0
You can get more ideas here: https://github.com/intuit/karate/issues/1191#issuecomment-650087023
Note that the argument to karate.fork() can take multiple forms. If you are using karate.exec() (which will block until the process completes) the same arguments work.
string - full command line as seen above
string array - e.g. ['script.sh', 'arg1']
json where the keys can be
line - string (OR)
args - string array
env - optional environment properties (as JSON)
redirectErrorStream - boolean, true by default which means Sys.err appears in Sys.out
workingDir - working directory
useShell - default false, auto-prepend cmd /c or sh -c depending on OS
And since karate.fork() is async, you need to call waitSync() if needed as in the example above.
Do provide feedback and we can tweak further if needed.
EDIT: here's a very advanced example that shows how to listen to the process output / log, collect the log, and conditionally exit: fork-listener.feature
Another answer which can be a useful reference: Conditional match based on OS
And here's how to use cURL for advanced HTTP tests ! https://stackoverflow.com/a/73230200/143475
In case you need to do a lot of local file manipulation, you can use the karate.toJavaFile() utility so you can convert a relative path or a "prefixed" path to an absolute path.
* def file = karate.toJavaFile('classpath:some/file.txt')
* def path = file.getPath()

powershell not expanding variable

I am trying to create a powershell script which installs a load of firewall policies.
I have a file firewalls.txt which has "firewall" "policy" on a single line. I then put that into a variable and try to call it using the "fwm load" command which is an external firewall application binary but the $fwPolstring is not being expanded within the command
$fwPol = Get-Content firewalls.txt
$fwPolString = $fwPol
fwm load "$fwPolString" 2>&1 > InstallLog.txt
I get error in InstallLog.txt
fwm : Missing targets
At C:\fw_estate_install.ps1:3 char:1
+ fwm load "$fwPolString" 2>&1 > InstallLog.txt

Cannot bind argument to parameter 'Path' because it is an empty string

I am trying to run custom script on windows AWS AMI. The steps I am using is as given here:
http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts-powershell.html
My Instance is already associated with IAM role and credential file path is set.
I am trying to run following command in power-shell:
.\mon-put-metrics-mem.ps1 -mem_util -mem_used -mem_avail -page_avail -page_used -page_util -memory_units Megabytes
The error I am getting is:
Cannot bind argument to parameter 'Path' because it is an empty string.
Your script is not able to see AWS_CREDENTIAL_FILE env var.
So try loading ur credential file
setx AWS_CREDENTIAL_FILE C:\aws\myCredentialFile.txt'
Then open a new powershell window because if you attempt to run it in the same window, it will not see the AWS_CREDENTIAL_FILE env var. Now try running
.\mon-put-metrics-mem.ps1 -mem_util -mem_used -mem_avail -page_avail -page_used -page_util -memory_units Megabytes -verbose

Run an .exe file with 1 input parameter from MATLAB

I have an .exe file developed in C# that is called by Matlab.
DirPath = '\\MYSERVER\PARENT_DIR\CHILD DIR\'
The old version of my command worked right
without input parameter: system( fullfile([DirPath 'NameOfExe']) )
The new version which requires an input parameter is failing. Can you please help me fix it?
I have tried many versions but the error is always:
'\MYSERVER\PARENT_DIR\CHILD' is not recognized as an internal or external command,
operable program or batch file.
With input parameter, FAIL:
strcommand = [ '''' fullfile([DirPath 'NameOfExe' ]) ' ' inputparameter '''' ];
eval(['[a,b]=system(' strcommand ')'])`
Correct usage when using CMD:
(say I: is my mapped drive to MYSERVER, & inputparameter is a path)
myroot:> cd I:
I:>cd PARENT_DIR\CHILD
I:\PARENT_DIR\CHILD>NameOfExe "inputparameter"