Execute powershell script with gitlab-runner on local windows machine - powershell

I do have following setup:
a win PC with gitlab-runner installed (working)
a powershell script running on the same PC is starting an application
a gitlab server to connect this local PC and starting the powershell script
Now when starting the powershell script directly from the local PC, the application starts and terminates after done - working as expected. When starting the same powershell script with the gitlab server (yml-file) then I can see that the application has been started (new process in taskmanager) but it is not running as well it never terminates.
When manually end the task I see that gitlab terminates again.
Question:
what could be the root cause?
is it possible to run the powershell script with gitlab-runner? I think there is a way with the command "exec". How does the command looks like when calling the powershell script?
is it possible to run the application not in the background in order to see whats going on?
others?
thanks in advance

I think there is a bug with the gitlab runner on windows.
No matter which shell you configure in the config.toml the runner
will always use cmd.exe for an exec local run.

Specify the --shell argument to override the default cmd.exe shell:
> gitlab-runner exec shell your_job --shell pwsh
If you run this locally in your project, it outputs to .builds/, so add this to your .gitignore because git will see it and think you might want to add a submodule.

Related

How to load environment variables in a remote AIX machine through ssh while running script from Jenkin pipeline?

We are using some custom modules in our Perl automation framework which runs through Jenkin pipeline. Recently we got package not found error for all custom modules while executing test cases in AIX servers as latest Perl version is installed there . So we tried to add "PERL5LIB" in the path as mentioned in document
https://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations
We added "export PERL5LIB=/home/foobar/code" in /etc/profile of the AIX server and script getting executed without any issue when running from local AIX machine.
Issue:
But we have Jenkin pipeline to execute the scripts in AIX server using ssh. Now when we do SSH to the AIX server in the pipeline script the variables that we have set in /etc/profile does not load and we get package not found error.
Question: How can I load the profile in the AIX server while running it from pipeline? or is there any other way to handle this. Before executing script I want to export PERL5LIB in remote AIX server through pipeline (only once) and the I should not get package not found error.
Below solutions I have tried :
Load the /etc/profile: ssh AIX server ./etc/profile (using dot since source not working in AIX)
Adding this line "export PERL5LIB=/home/foobar/code" in .ssh/environment in AIX server and set PermitUserEnviorment yes
Appreciate any help on this.
Assign values to variables the usual way:
ssh user#host 'export PERL5LIB=/somepath; echo $PERL5LIB'
user#hosts's password:
/somepath
or
ssh user#host '. /etc/profile.local; echo $PERL5LIB'
user#hosts's password:
/somepath/from/profile
Edit:
If you have to execute multiple commands, create a script and upload it to the target computer, for example:
SCRIPTNAME=/tmp/$$.$RANDOM.script
scp myscript.sh user#host:"$SCRIPTNAME"
ssh user#host "$SCRIPTNAME"
This is solved with below changes.
Step 1: Edit ~/.ssh/environment. Add variable PERL5LIB="/path of the module/"
Step 2: Edit /etc/ssh/sshd_config. Change variable PermitUserEnvironment from no to yes. Uncomment it if commented. This will enable access of environment variables to SSH.
Step 3: Restart SSHD service. (This is imp. I had tried step 1 and 2 before also but not restarted the service so solution was not working)
We can create a script and run it before executing automation test from pipeline.

Run a script to load commands into my main script

I have a powershell file that I have downloaded from ScriptCenter that allows me to control and query virtual desktops on my machine (https://gallery.technet.microsoft.com/scriptcenter/Powershell-commands-to-d0e79cc5).
Using their example, I can run that ps1 file at the start of my script to use those commands that the script creates. All fine here.
The only issue with this is that when I run my script, it asks to confirm to run it. This is something I don't want my script to do.
To work around this, I tried using the "PowerShell" command with "-ExecutionPolicy Bypass" set. This removes the prompt to approve the script, however it stops the script from being loaded into my scripts session as I can't use any of the commands it make available by running it.
How do I either run the script first, without it prompting, or execute the powershell command so that it is run in the session space of my script so that its commands are available?
Thanks

Jenkins windows slave batch job says success but job did not run

Trying to set up a jenkins v2.46.3 slave on windows 2016 server to run a batch file.
It looks like it is working but the batch file does not actually run. The script does not generate the expected log file and nothing shows up in task manager on the slave
The console output of the job looks like this:
Started by user xxx
Building remotely on xxx-Windows (windows) in workspace c:\Jenkins\workspace\xxx
[xxx] $ cmd /c call C:\Windows\TEMP\hudson4948156451026881586.bat
c:\Jenkins\workspace\xxx>C:\QA\xxx\Perl\Tests\runxxxTests.bat
c:\Jenkins\workspace\xxx>cd C:\QA\xxx\Perl\Tests
C:\QA\xxx\Perl\Tests>runxxxTests.pl -f test_suite_test.list
Finished: SUCCESS
If I run the batch file manually it works as expected.
There do not seem to be any errors. How can I troubleshoot this further ?
The fix to this was changing the log on rights of the Jenkins and Jenkins Agent services on the windows slave from LocalSystem to a privileged account.

Is it possible to log all powershell commands run on a machine?

We have some .net applications running on a server that run powershell scripts. Is there a setting where we can log every single powershell command run on that machine, without modifying our existing applications? I already tried start-transcript . That command only captures the commands run in the current session.
I believe Microsoft calls what you're after "Over the Shoulder Transcription". It's described here, and will be available in WMF5.

Powershell and ssh when running rabbit

I have ssh on to a ubuntu box and run the following:
rabbitmq-server –detached
Which I believe should give me the command prompt back and run rabbit in the background, howerver it justs hangs:
Is this a powershell issue?
PowerShell is a component of Microsoft Windows, it has a command-line shell and a scripting environment. So I don't think you question is relative to PowerShell.