Using: Pool: Azure Pipelines · Agent: Hosted Agent
First Release contained only 2 tasks:
Powershell inline script which writes "Hello world"
Powershell on Azure subscription inline script which writes "Hello world"
It worked fine.
After I added additional tasks:
Executing our PowerShell script
.4 Deploy to Kubernetes tasks.
Created Release with system.debug and it failed on the first task with an error:
2020-05-20T06:57:10.3710666Z ##[error]The term 'powershell.exe' 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.
Executing with system.debug gave this output:
2020-05-20T07:15:13.9833585Z ##[debug]Evaluating condition for step: 'Hello World'
2020-05-20T07:15:13.9843565Z ##[debug]Evaluating: succeeded()
2020-05-20T07:15:13.9844512Z ##[debug]Evaluating succeeded:
2020-05-20T07:15:13.9845838Z ##[debug]=> True
2020-05-20T07:15:13.9846542Z ##[debug]Result: True
2020-05-20T07:15:13.9847415Z ##[section]Starting: Hello World
2020-05-20T07:15:14.0314856Z ==============================================================================
2020-05-20T07:15:14.0315650Z Task : PowerShell
2020-05-20T07:15:14.0317519Z Description : Run a PowerShell script on Linux, macOS, or Windows
2020-05-20T07:15:14.0317953Z Version : 2.169.0
2020-05-20T07:15:14.0318548Z Author : Microsoft Corporation
2020-05-20T07:15:14.0319259Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2020-05-20T07:15:14.0319792Z ==============================================================================
2020-05-20T07:15:15.8622679Z ##[debug]VstsTaskSdk 0.11.0 commit 7ff27a3e0bdd6f7b06690ae5f5b63cb84d0f23f4
2020-05-20T07:15:16.0680294Z ##[debug]Entering D:\a\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.169.0\powershell.ps1.
2020-05-20T07:15:16.0782094Z ##[debug]Loading resource strings from: D:\a\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.169.0\task.json
2020-05-20T07:15:16.1340432Z ##[debug]Loaded 11 strings.
2020-05-20T07:15:16.1343861Z ##[debug]SYSTEM_CULTURE: 'en-US'
2020-05-20T07:15:16.1345219Z ##[debug]Loading resource strings from: D:\a\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.169.0\Strings\resources.resjson\en-US\resources.resjson
2020-05-20T07:15:16.1597086Z ##[debug]Loaded 11 strings.
2020-05-20T07:15:16.1959084Z ##[debug]INPUT_ERRORACTIONPREFERENCE: 'stop'
2020-05-20T07:15:16.2027000Z ##[debug]INPUT_FAILONSTDERR: 'false'
2020-05-20T07:15:16.2028272Z ##[debug] Converted to bool: False
2020-05-20T07:15:16.2041964Z ##[debug]INPUT_IGNORELASTEXITCODE: 'false'
2020-05-20T07:15:16.2056755Z ##[debug] Converted to bool: False
2020-05-20T07:15:16.2081737Z ##[debug]INPUT_PWSH: 'false'
2020-05-20T07:15:16.2100091Z ##[debug] Converted to bool: False
2020-05-20T07:15:16.2122826Z ##[debug]INPUT_WORKINGDIRECTORY: 'D:\a\r1\a'
2020-05-20T07:15:16.2247526Z ##[debug]Asserting container path exists: 'D:\a\r1\a'
2020-05-20T07:15:16.2273044Z ##[debug]INPUT_TARGETTYPE: 'inline'
2020-05-20T07:15:16.2307533Z ##[debug]INPUT_SCRIPT: '# Write your PowerShell commands here.
2020-05-20T07:15:16.2320023Z ##[debug]
2020-05-20T07:15:16.2331579Z ##[debug]Write-Host "Hello World"'
2020-05-20T07:15:16.2375904Z Generating script.
2020-05-20T07:15:16.2515233Z ##[debug]AGENT_VERSION: '2.168.2'
2020-05-20T07:15:16.2594226Z ##[debug]AGENT_TEMPDIRECTORY: 'D:\a\_temp'
2020-05-20T07:15:16.2614777Z ##[debug]Asserting container path exists: 'D:\a\_temp'
2020-05-20T07:15:27.6754436Z ##[debug]Leaving D:\a\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.169.0\powershell.ps1.
2020-05-20T07:15:27.9496049Z ##[debug]Caught exception from task script.
2020-05-20T07:15:27.9529115Z ##[debug]Error record:
2020-05-20T07:15:28.0379597Z ##[debug]The term 'powershell.exe' 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.
2020-05-20T07:15:28.0395647Z ##[debug] + CategoryInfo : ObjectNotFound: (powershell.exe:String) [], CommandNotFoundException
2020-05-20T07:15:28.0402331Z ##[debug] + FullyQualifiedErrorId : CommandNotFoundException
2020-05-20T07:15:28.0412871Z ##[debug]
2020-05-20T07:15:28.0433105Z ##[debug]Script stack trace:
2020-05-20T07:15:28.0479363Z ##[debug]
2020-05-20T07:15:28.1031586Z ##[debug]Exception:
2020-05-20T07:15:28.1168338Z ##[debug]System.Management.Automation.CommandNotFoundException: The term 'powershell.exe' 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.
2020-05-20T07:15:28.1325804Z ##[error]The term 'powershell.exe' 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.
2020-05-20T07:15:28.1338779Z ##[debug]Processed: ##vso[task.logissue type=error]The term 'powershell.exe' 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.
2020-05-20T07:15:28.1347561Z ##[debug]Processed: ##vso[task.complete result=Failed]
2020-05-20T07:15:28.2164053Z ##[section]Finishing: Hello World
Note.
Don't name your variable path in the Azure DevOps pipeline, because it will rewrite an environment variable PATH.
After renaming my variable it worked again and was able to find all tools.
In MS documentation it's not mentioned, so I created a ticket for them.
Related
I am getting this error:
Generating script.
Script contents:
docker run -p 9988:1433 aneste:mssql
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\31deb425-e236-4cf3-bfe7-aed9ce46dd35.cmd""
.\start : The term '.\start' 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:76
+ ... e = 'Stop'; $ProgressPreference = 'SilentlyContinue'; .\start -sa_pas ...
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\start:String) [], ParentConta
insErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
##[error]Cmd.exe exited with code '1'.
I have tried to search for a solution for a while now but can't seem to find one, not eaven sure what causes it, docker ls outputs the docker image correctly.
EDIT:
Yaml file
I am getting the error below:
2020-09-17T10:05:00.724 [Error] ERROR: Error logging into WVD: The
term 'Get-AutomationPSCredential' 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.Exception :Type :
Microsoft.PowerShell.Commands.WriteErrorExceptionMessage : Error
logging into WVD: The term 'Get-AutomationPSCredential' 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.HResult :
-2146233087CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExceptionFullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorException,_TimerTrigger1_InvocationInfo
:MyCommand : _TimerTrigger1_HistoryId : 1InvocationName :
_TimerTrigger1_CommandOrigin : InternalScriptStackTrace : at <ScriptBlock>, D:\home\site\wwwroot\TimerTrigger1\run.ps1: line
158Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result:
ERROR: Error logging into WVD: The term 'Get-AutomationPSCredential'
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.Exception
:Type : Microsoft.PowerShell.Commands.WriteErrorExceptionMessage :
Error logging into WVD: The term 'Get-AutomationPSCredential' 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.HResult :
-2146233087CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExceptionFullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorException,_TimerTrigger1_InvocationInfo
:MyCommand : _TimerTrigger1_HistoryId : 1InvocationName :
_TimerTrigger1_CommandOrigin : InternalScriptStackTrace : at <ScriptBlock>, D:\home\site\wwwroot\TimerTrigger1\run.ps1: line
158Exception: Error logging into WVD: The term
'Get-AutomationPSCredential' 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.Stack:
I have seen information online that suggests it is part of the module "AzureAutomationAuthoringToolkit", but I don't understand how I install this into the environment the Function App runs in.stuff and am following a blog post below to try and get the auto-start up shut down working. I am fairly certain that I have followed this correctly. To me the error suggests that the environment doesn't have the module loaded.
https://www.ciraltos.com/auto-start-and-stop-session-hosts-in-windows-virtual-desktop-spring-update-arm-edition-with-an-azure-function/
I don't think you can use the command Get-AutomationPSCredential in the azure function, it is an Internal cmdlet belongs to the internal module Orchestrator.AssetManagement.Cmdlets, it is only available when you're executing runbooks in the Azure sandbox environment, or on a Windows Hybrid Runbook Worker.
So in your case, your option is to use the script in the automation powershell runbook, then use Invoke-WebRequest in the timer trigger to invoke the web request to the webhook URL of the runbook to start the runbook(As the script should be ran every 5 mins said by author).
Invoke-WebRequest -Uri <Webhook URI> -Method Post
For more details, you could refer to the link mentioned in the Github repo.
I am trying to pass a system variable to the python script from azure devops. This is what I currently have in Yaml file:
- script: pytest test/test_pipeline.py
--$(global_variable)
--junitxml=$(Build.StagingDirectory)/test_pipeline-results.xml
displayName: 'Testing Pipeline'
condition: always()
The variable I need in my script is $(global_variable). The variable contains a value of $(Build.SourcesDirectory). It is the global variable. I am getting an error message as "unrecognised arguments" when I run the job.
Any help to tackle this will be helpful.
Thanks!
EDIT:
Complete log:
`##[section]Starting: Testing Pipeline
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.151.2
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
pytest test/test_pipeline.py --my_param="/home/vsts/work/1/s" --junitxml=/home/vsts/work/1/a/test_pipeline-results.xml
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/64fb4a65-90de-42d5-bfb3-58cc8aa174e3.sh
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --my_param=/home/vsts/work/1/s
inifile: None
rootdir: /home/vsts/work/1/s
##[error]Bash exited with code '4'.
##[section]Finishing: Testing Pipeline`
I tried to write a simple sample for you refer.
In your .py file, please use add_argument to read in the command line parameter. In this issue, this command line parameter comes from your task specified.
A.py file:
import argparse
def parse_argument():
parse = argparse.ArgumentParser(description="ForTest!")
parse.add_argument("-test_data")
parse.add_argument("-build_dir")
And then, in PythonScript#0 task:
scriptPath: ‘A.py’
argument: -test_data $(myVariable1) -build_dir $(myVariable2)
myVariable1 and myVariable2 are all my customized variable. You can all use environment variable.
Since in python script, add_argument is used to read in the parameter which from command line. So it can receive the value from Argument specified.
In addition, for the issue which in your question, I think you’d better delete the content from your script: --my_param="/home/vsts/work/1/s" and try again. Because --my_param could not the valid argument for pytest.
Hope can help you.
I'm trying to download and run a PowerShell script (from blob storage) using the Run Powershell artifact on an existing VM in Azure DevTest labs.
I get the following error and I assume I am doing something stupid.
& : The term './script.ps1' 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:3
+ & ./script.ps1
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./script.ps1:String) [], Comman
dNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Here is my setup...
I have also tried the JSON array syntax, which gave the same result, and an invalid URL which gave a 404 error so it seems as if it is downloading my script but then failing to find it.
Below is info I wrote a while back.
Few items to note:
Folder structure is not supported as of this writing. Therefore, script needs to be at the root of the container
Ensure your blob is public
First you will need your file in Azure storage. Once uploaded in your container, click the file to get to its properties and copy the URL field.
As an example, I have created the following Run.ps1 script file and uploaded it to storage as a blob:
param ( [string]$drive = "c:\" )
param ( [string]$folderName = "DefaultFolderName" )
New-Item -Path $drive -Name $folderName -ItemType "directory"
Now, while adding the 'Run PowerShell' artifact to the VM, we provide the following information:
File URI(s): URL field copied from earlier step. (eg. https://myblob.blob.core.windows.net/mycontainer/Run.ps1)
Script to Run: Name of the PS1 script, (eg. Run.ps1)
Script Arguments: Arguments as you would write them at the end of your command (eg. -drive "d:\" -folderName "MyFolder")
I am trying to automatically publish all the projects of my .NET solution using the DeplyOnBuild=true argument (according to this answer )
I typed this command in the PowerShell:
msbuild mysolultion.sln /p:Configuration=Debug;DeployOnBuild=true;
But I get the following error message :
The term 'DeployOnBuild=true' 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:59
+ msbuild mysolution.sln /p:Configuration=Debug;DeployOnBuild=true <<<< ;
+ CategoryInfo : ObjectNotFound: (DeployOnBuild=true:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I am not sure what I am doing wrong.
PowerShell is interpreting everything after your first semicolon as a separate command.
You need to use quotes:
MSBuild example.sln /p:"Configuration=Debug;DeployOnBuild=true;"
Or use separate /p parameters:
MSBuild example.sln /p:Configuration=Debug /p:DeployOnBuild=true