How to use a windows vm on virtualbox gitlab runner? - gitlab

I'm trying to run a windows vm in virtualbox and use it as a runner in git lab, following https://docs.gitlab.com/runner/executors/virtualbox.html#use-native-openssh-and-powershell
I installed native open ssh, git for windows and configured the default shell to be pwsh as they request:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "$PSHOME\pwsh.exe" -PropertyType String -Force
however SSH does not work. When I try to ssh to localhost:
ssh MACHINE_NAME\username#localhost
I get Permission denied, try again
when I do this. If I do
reg add HKLM\SOFTWARE\OpenSSH /v DefaultShell /d C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
then I can ssh into my machine. THe gitlab can also, but then it complains that bash is not a command on power shell:
00:02
bash : The term 'bash' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path
is correct and try again.
At line:1 char:1
+ bash -l
+ ~~~~
+ CategoryInfo : ObjectNotFound: (bash:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
ERROR: Job failed: prepare environment: Process exited with status 1. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information
To fix that, I installed WSL and ubuntu on Windows, but then it gives
ERROR: Job failed: prepare environment: Process exited with status 1. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information
this is a known problem in ubuntu which is fixed by removing .bash_logout but I can't do this to the WSL image. Also, installing WSL shouldn't be the way here, it should work without WSL.

Related

Get-AzurePublishSettingFile : The term 'Get-AzurePublishSettingFile' is not recognized

I have tried installing the Azure and AZ cmdlet via the command with AllowClobber and that successfully installed. I am running PowerShell as administrator and have connected my Azure account by signing in. However, when running the command "Get-AzurePublishSettingFile" the following error appears:
Get-AzurePublishSettingFile : The term 'Get-AzurePublishSettingFile' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
Get-AzurePublishSettingFile
+ CategoryInfo : ObjectNotFound: (Get-AzurePublishSettingFile:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Make sure you have installed the ASM PowerShell module Azure, and I notice you missed an s in your command, it should be Get-AzurePublishSettingsFile, not Get-AzurePublishSettingFile.
Reference - https://learn.microsoft.com/en-us/powershell/module/servicemanagement/azure.service/get-azurepublishsettingsfile?view=azuresmps-4.0.0

Installing git-secrets on Windows

I've been trying to get git-secrets installed for the last couple of hours, and can not seem to figure it out. Google searching gets me almost nothing, almost all of the results are for git-secret (singular secret, not plural).
I cloned the folder to my computer and opened WindowsPower Shell in Administrator mode to run the install.ps1 file.
This is the output that I got from PowerShell:
Checking to see if installation directory already exists...
Creating installation directory.
Copying files.
Copy-Item : Cannot find path 'C:\windows\system32\git-secrets' because it does not exist.
At C:\Users\ricci\Downloads\git-secrets\install.ps1:15 char:1
+ Copy-Item ./git-secrets -Destination $InstallationDirectory -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\windows\system32\git-secrets:String) [Copy-Item], ItemNotF
oundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
Copy-Item : Cannot find path 'C:\windows\system32\git-secrets.1' because it does not exist.
At C:\Users\ricci\Downloads\git-secrets\install.ps1:16 char:1
+ Copy-Item ./git-secrets.1 -Destination $InstallationDirectory -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\windows\system32\git-secrets.1:String) [Copy-Item], ItemNo
tFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
Checking if directory already exists in Path...
Already in Path.
Adding to user session.
Done.
When I run git secrets --register-aws --global in a repo directory it returns git: 'secrets' is not a git command. See 'git --help'
Any idea what I need to do or where I can look for help?
Thanks
install.ps1 includes:
Param([string]$InstallationDirectory = $($Env:USERPROFILE + "\.git-secrets"))
It appears $Env:USERPROFILE is, in your session, C:\Windows\System32, which is not good.
Try and open a Powershell session:
as your own Windows account (not admin)
within your %USERPROFILE% Path (C:\Users\xxx) instead of C:\Windows\System32

Get-AzsHealthReport is not recognized

I tried to get Azure Stack identity health report according to the below document. But getting error if the packages are installed on power shell.
Link
Get-AzsHealthReport : The term 'Get-AzsHealthReport' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:3 char:17
+ $healthReport = Get-AzsHealthReport -AdminResourceManagerEndpoint $Ad ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AzsHealthReport:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Follow the steps provided in this document on powershell as Admin.
Start Powershell in Admin mode and run the below steps:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
# Install the AzureRM.BootStrapper module. Select Yes when prompted to install NuGet
Install-Module -Name AzureRM.BootStrapper
# Install and import the API Version Profile required by Azure Stack into the current PowerShell session.
Use-AzureRmProfile -Profile 2019-03-01-hybrid -Force
Install-Module -Name AzureStack -RequiredVersion 1.7.2
Now install Azure Stack Tools:
https://github.com/Azure/AzureStack-Tools/tree/master/Identity#download-azure-stack-tools
cd C:
mkdir Azure-Stack
cd .\Azure-Stack\
# Download the tools archive.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
invoke-webrequest `...
# Expand the downloaded files.
expand-archive master.zip `...
# Change to the tools directory.
cd AzureStack-Tools-master
cd .\Identity\
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Import-Module ..\Connect\AzureStack.Connect.psm1
Import-Module ..\Identity\AzureStack.Identity.psm1
Get-AzsHealthReport
You should now be able to run the command.
Hope this helps!

Issue while creating azure container instance

I am able to run the docker image and container works fine in local as expected.
After pushing the docker image to Azure Container Registry, I've tried to run through Azure Container Instance and throwing below error. Whereas the PS file is located in the WORKDIR and its working in local. Would be great if someone can help.
Dockerfile
WORKDIR c:/inetpub/wwwroot
ENTRYPOINT powershell .\InitializeContainer
Error:
.\InitializeContainer : The term '.\InitializeContainer' is not recognized as
the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ .\InitializeContainer
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\InitializeContainer:String) [
], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Azure DevOps build pipeline with hosted agent failing

I am pretty new to Azure and TFS and related. So please excuse me if I mix up the terms here.
I am testing the capabilities of Microsoft Team Foundation Server with an on-premise installation. I am not the admin of the server itself, I have admin access to one of the projects inside.
I have a git repo with some python code in this project and I am trying to set up CI build pipeline for this. I am also manually configuring an agent to run this build pipeline. For the timebeing, I am configuring the windows machine that I am working on to run as an agent. I was able to set it up to listen for jobs and also it picks up the job when submitted from the TFS server. (I am running the agent from a cmd.exe window)
However, I couldn't get it do even the simplest of command line tasks as part of the build pipeline.
Below is the output of where python:
2019-08-27T14:41:15.1614046Z ##[section]Starting: Find python version
2019-08-27T14:41:15.1623937Z ==============================================================================
2019-08-27T14:41:15.1624042Z Task : Command Line
2019-08-27T14:41:15.1624091Z Description : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-08-27T14:41:15.1624157Z Version : 2.146.1
2019-08-27T14:41:15.1624203Z Author : Microsoft Corporation
2019-08-27T14:41:15.1624258Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-08-27T14:41:15.1625058Z ==============================================================================
2019-08-27T14:41:15.6151701Z Cannot invoke method. Method invocation is supported only on core types in this language mode.
2019-08-27T14:41:15.6151921Z At line:1 char:1
2019-08-27T14:41:15.6151968Z + . ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPa ...
2019-08-27T14:41:15.6152019Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-08-27T14:41:15.6152077Z + CategoryInfo : InvalidOperation: (:) [], RuntimeException
2019-08-27T14:41:15.6152123Z + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
2019-08-27T14:41:15.6152156Z
2019-08-27T14:41:17.7569608Z Cannot invoke method. Method invocation is supported only on core types in this language mode.
2019-08-27T14:41:17.7569833Z At line:1 char:740
2019-08-27T14:41:17.7570630Z + ... Continue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create ...
2019-08-27T14:41:17.7571090Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-08-27T14:41:17.7572452Z + CategoryInfo : InvalidOperation: (:) [], RuntimeException
2019-08-27T14:41:17.7574051Z + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
2019-08-27T14:41:17.7574178Z
2019-08-27T14:41:17.8271008Z ##[error]Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name 'C:\TOOLS\agent\_work\_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.146.1\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList #{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\TOOLS\agent\_work\_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.146.1\cmdline.ps1'''))"'.
2019-08-27T14:41:17.8301183Z ##[section]Finishing: Find python version
This command runs fine when I execute it from a commandline interactively in my machine.
Why is the PowerShell getting invoked when the pipeline runs? And why such a long command to execute something so simple?
Thanks in advance for any suggestions you can give.
The agent uses PowerShell behind the scenes, it looks like your IT put some security in the computers that blocked running some PowerShell scripts (maybe only it from remote).
Try to run it in your PowerShell:
$ExecutionContext.SessionState.LanguageMode
I guess you will get this output:
ConstrainedLanguage
If yes, try to switch it to FullLanguage:
$ExecutionContext.SessionState.LanguageMode = "FullLanguage"
If it doesn't help maybe it's also blocked, so you need to talk with IT that will change it or try to change the registry like explained here or set the environment variable __PSLockdownPolicy to 0.

Resources