Azure DevOps build pipeline with hosted agent failing - azure

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.

Related

New-Object : Cannot find type [Microsoft.Open.AzureAD.Model.DomainFederationSettings]: verify that the assembly

I am following documentation https://learn.microsoft.com/en-us/azure/active-directory/b2b/direct-federation on Powershell and running below command:
Import-Module AzureAD
Connect-AzureAD
$federationSettings = New-Object Microsoft.Open.AzureAD.Model.DomainFederationSettings
I am getting following error:
PS C:\WINDOWS\system32> $federationSettings = New-Object Microsoft.Open.AzureAD.Model.DomainFederationSettings
New-Object : Cannot find type [Microsoft.Open.AzureAD.Model.DomainFederationSettings]: verify that the assembly
containing this type is loaded.
At line:1 char:23
+ ... nSettings = New-Object Microsoft.Open.AzureAD.Model.DomainFederationS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
DomainFederationSettings class seems to be missing
How can I have Microsoft.Open.AzureAD.Model.DomainFederationSettings loaded and execute command $federationSettings = New-Object Microsoft.Open.AzureAD.Model.DomainFederationSettings
at the time of writing this answer, you need to use AzureADPreview module and not AzureAd
I highly suspect you are trying this statement with the latter rather than the former.
To install
Install-Module -Name AzureADPreview -AllowClobber
(-AllowClobber is to allow the installation side-to-side with AzureAD module, if you have it installed)
To configure direct federation in Azure AD using PowerShell
Install the latest version of the Azure AD PowerShell for Graph module
(AzureADPreview). (If you need detailed steps, the quickstart for
adding a guest user includes the section Install the latest
AzureADPreview module.)
Source :
MS docs - Configure direct federation in azure ad using powershell

Get-MgApplication is not recognized as the name of a cmdlet - Power Shell

I am trying to run Contoso Monetization Code Sample Web App provided by Microsoft as a starting point for moving from paid add-in to SaaS offering. I am stuck at the very end where I am meant to be updating the Azure Active Directory Applications. I get this error
Get-MgApplication : The term 'Get-MgApplication' 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.
+ $webApp = Get-MgApplication -top 400|Where-Object {$_.DisplayName -eq ...+ CategoryInfo : ObjectNotFound: (Get-MgApplication:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Here is the code referencing the 'Get-MgApplication'.
$webApp = Get-MgApplication -top 400|Where-Object {$_.DisplayName -eq $webAppDisplayName}
$webAppSiteName = $armConfigJson.parameters.webAppSiteName.value
$redirectUris = "https://$webAppSiteName.azurewebsites.net/signin-oidc","https://$webAppSiteName.azurewebsites.net/"
Update-MgApplication -ApplicationId $webApp.Id -WebRedirectUris $redirectUris
I have checked online without any success to find if this module can be imported and loaded. I have also checked using the command get-Module to check if is in the power shell module folder and probable misspelled but it not there as well. Any help will be much appreciated.
You need to install the Microsoft.Graph.Beta cmdlets - https://github.com/microsoftgraph/msgraph-sdk-powershell/tree/master

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!

Use deploy script on Azure release pipeline

I've created a successful build and release that deployed my React app on a Azure Web App environment. The app I created will be deployed on many different customer environments and I don't want to create each app-service myself so I want to automate that proces. I've exported the template and now I have a deploy.psh1 file with a parameters.json and a template.json file. But I'm unsure on what to do now.
I've tried adding a powershell task to my release step and paste in the contents of deploy.sh1 in the inline section but that results in multiple errors:
2019-05-30T19:16:31.9475172Z ##[section]Starting: PowerShell Script
2019-05-30T19:16:31.9534016Z ==============================================================================
2019-05-30T19:16:31.9534117Z Task : PowerShell
2019-05-30T19:16:31.9534203Z Description : Run a PowerShell script on Windows, macOS, or Linux.
2019-05-30T19:16:31.9534274Z Version : 2.148.0
2019-05-30T19:16:31.9534351Z Author : Microsoft Corporation
2019-05-30T19:16:31.9534429Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
2019-05-30T19:16:31.9534519Z ==============================================================================
2019-05-30T19:16:32.8910231Z Generating script.
2019-05-30T19:16:32.9442109Z ========================== Starting Command Output ===========================
2019-05-30T19:16:32.9667917Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\c37bf4b5-41a1-4125-b7c3-04e0c77fe403.ps1'"
2019-05-30T19:16:33.2330921Z At C:\agent\_work\_temp\c37bf4b5-41a1-4125-b7c3-04e0c77fe403.ps1:30 char:10
2019-05-30T19:16:33.2331159Z + [string]
2019-05-30T19:16:33.2331234Z + ~
2019-05-30T19:16:33.2331512Z Missing closing ')' in expression.
2019-05-30T19:16:33.2332867Z At C:\agent\_work\_temp\c37bf4b5-41a1-4125-b7c3-04e0c77fe403.ps1:49 char:1
2019-05-30T19:16:33.2333119Z + )
2019-05-30T19:16:33.2333839Z + ~
2019-05-30T19:16:33.2334117Z Unexpected token ')' in expression or statement.
2019-05-30T19:16:33.2335145Z At C:\agent\_work\_temp\c37bf4b5-41a1-4125-b7c3-04e0c77fe403.ps1:29 char:2
2019-05-30T19:16:33.2335362Z + [Parameter(Mandatory=$True)]
2019-05-30T19:16:33.2336143Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-05-30T19:16:33.2336345Z Unexpected attribute 'Parameter'.
2019-05-30T19:16:33.2337371Z At C:\agent\_work\_temp\c37bf4b5-41a1-4125-b7c3-04e0c77fe403.ps1:40 char:2
2019-05-30T19:16:33.2337639Z + [Parameter(Mandatory=$True)]
2019-05-30T19:16:33.2338286Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-05-30T19:16:33.2338534Z Unexpected attribute 'Parameter'.
2019-05-30T19:16:33.2339929Z + CategoryInfo : ParserError: (:) [], ParseException
2019-05-30T19:16:33.2340251Z + FullyQualifiedErrorId : MissingEndParenthesisInExpression
2019-05-30T19:16:33.2340819Z
2019-05-30T19:16:33.3687310Z ##[error]PowerShell exited with code '1'.
2019-05-30T19:16:33.3968831Z ##[section]Finishing: PowerShell Script
So my question is how do I add the creation of the app-service during my release?
There is a Resource Group deployment task which you can use directly to deploy ARM templates: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops
It takes your parameters.json and template.json as input.

Unable to deploy proxy to apigee using apigeetool

Thanks joey, I am using the below commands from Jenkins but getting errors.
Set-ExecutionPolicy RemoteSigned
Import-Module PowerShellGet
Install-Module -Name PSApigeeEdge -Force
Import-module PSApigeeEdge
Set-EdgeConnection -org def -User xyz-EncryptedPassword abc
Deploy-EdgeApi -Name proxy-name -Environment digital-dev -Revision 25 Error: ConvertTo-SecureString : Input string was not in a correct format.
At C:\Program Files\WindowsPowerShell\Modules\PSApigeeEdge\Public\Set-EdgeConnection.ps1:97 char:35
+ $SecurePass = ConvertTo-SecureString -String $EncryptedPassw ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertTo-SecureString], FormatException
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
There is another tool you can use if you are comfortable with powershell.
https://github.com/DinoChiesa/Edge-Powershell-Admin
The powershell module will need to be imported in order to work with the module, which is pretty simple in jenkins.
ADT can help deploy apiproxies/shared-flows. It has detailed documentation on setting up and using the tool.

Resources