Search code examples
gitfunctionpowershellsshpowershell-remoting

ssh into windows server from git-ci and execute a powershell fucntion with parameter


I'm trying to execute a powershell function inside my powershell file after ssh-ing into my windows server from my git server.

this is the code I'm using:

script:
  stage: before_merge
  script: 
  - sshpass -p <<password>> ssh user@host powershell.exe -File G:\test\Scripts\test1.ps1 -Command "test 2"
  only:
  - merge_requests

and this is the code inside test1.ps1

function test($no){
    $message = "test" + $no
    Add-Content G:\MIERUKA\Scripts\test1.txt $message
} 

when I run the ci code from my git-ci, the result itself are a success. but, the file is not created. it just like my function is not executed in the first place


Solution

  • after tweaking a little bit, got my answer. this is the code that I use:

    script:
      stage: before_merge
      script: 
      - sshpass -p <<password>> ssh user@host "cmd.exe /c powershell.exe G:\path\toScripts\test1.ps1; "test 2""
      only:
      - merge_requests