Devops Proxy Configuration for tasks, not for agent - azure-devops

This my scenario:
Azure DevOps Server Version Dev17.M153.3
Self-hosted Agent Agent.Version 2.177.1
Source Control Type TFVC
The Agent is working well without proxy configuration, the problem are 2 tasks it executes.
After getting the source code, the pipeline have two NuGet tasks:
First the NuGet Tool Installer task
Second the NuGet Task
I get the following error in the first task
##[debug]Agent.Version=2.177.1
##[debug]Agent.ToolsDirectory=C:\Proyectos\Agent2\_work\_tool
##[debug]isExplicit: 5.10.0
##[debug]explicit? true
##[debug]evaluating 1 versions
##[debug]matched: 5.10.0
##[debug]Querying versions list
##[debug]Agent.ProxyUrl=undefined
ERR:connect ETIMEDOUT 152.199.23.209:443
##[debug]task result: Failed
##[debug]Processed: ##vso[task.complete result=Failed;]
Then I configure these Pipeline variables
Agent.ProxyBypassList $(ProxyBypassList)
Agent.ProxyPassword $(ProxyPassword)
Agent.ProxyUrl $(ProxyUrl)
Agent.ProxyUsername $(ProxyUsername)
The values are defined in a Variable Group.
With this configuration, the task works well
##[debug]Agent.Version=2.177.1
##[debug]Agent.ToolsDirectory=C:\Proyectos\Agent2\_work\_tool
##[debug]evaluating 0 versions
##[debug]match not found
##[debug]Querying versions list
##[debug]Agent.ProxyUrl=***
##[debug]Agent.ProxyUsername=***
##[debug]Agent.ProxyPassword=***
##[debug]Agent.ProxyBypassList=***
(node:15928) Warning: Use Cipheriv for counter mode of aes-256-ctr
##[debug]evaluating 53 versions
##[debug]matched: 5.10.0
##[debug]Found the following version from the list: 5.10.0
##[debug]isExplicit: 5.10.0
##[debug]explicit? true
##[debug]Agent.Version=2.177.1
##[debug]Agent.ToolsDirectory=C:\Proyectos\Agent2\_work\_tool
##[debug]checking cache: C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64
##[debug]not found
##[debug]Downloading version: 5.10.0
...
##[debug]Processed: ##vso[task.prependpath]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64
##[debug]set NuGetExeToolPath=C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe
##[debug]Processed: ##vso[task.setvariable variable=NuGetExeToolPath;issecret=false;]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe
Then the problem is traslated to the second tasks. This is the generated YAML of the second tasks:
steps:
- task: NuGetCommand#2
displayName: 'NuGet restore packages.config'
inputs:
restoreSolution: '**/packages.config'
feedsToUse: config
nugetConfigPath: 'xxxxxxxxxx\NuGet.Config'
externalFeedCredentials: 'xxxxxxxxx Basic Authentication'
The external Feed Credentials is a Service Connection to a private feed in another DevOps collection of the same server. I have also tried using a Service Connection with a Token and getting the same result.
This is part of the log of this task
Versión de NuGet detectada: 5.10.0.7240 / 5.10.0+dca1d060f38e1e02f6bfca41e25f081f19fd534b.dca1d060f38e1e02f6bfca41e25f081f19fd534b
##[debug]Quirks for 5.10.0.7240:
##[debug] NoTfsOnPremAuthConfig
##[debug] V2CredentialProvider
##[debug]NuGet.ForceEnableCredentialProvider=undefined
##[debug]Credential provider V1 is disabled in favor of V2 plugin.
##[debug]NuGet_ForceEnableCredentialProviderV2=undefined
##[debug]NuGetTasks.IsHostedTestEnvironment=undefined
##[debug]System.ServerType=OnPremises
##[debug]V2 credential provider is enabled.
##[debug]NuGet.ForceEnableCredentialConfig=undefined
##[debug]NuGetTasks.IsHostedTestEnvironment=undefined
##[debug]System.ServerType=OnPremises
##[debug]Credential config is disabled due to on-prem quirks.
##[debug]Setting up auth
##[debug]Discovered URL prefixes: http://xxxxxxxxx:8080/tfs/xxxxxxxx/
##[debug]NuGetTasks.ExtraUrlPrefixesForTesting=undefined
##[debug]Getting credentials for local feeds
SYSTEMVSSCONNECTION exists true
##[debug]SYSTEMVSSCONNECTION exists true
##[debug]Got auth token
##[debug]externalEndpoints=bf184c95-f3f5-4dcf-be45-9aa22eba92e9
##[debug]bf184c95-f3f5-4dcf-be45-9aa22eba92e9=http://xxxxxxx:8080/tfs/xxxxxxxx/_packaging/xxxxxxxx/nuget/v3/index.json
bf184c95-f3f5-4dcf-be45-9aa22eba92e9 exists true
##[debug]bf184c95-f3f5-4dcf-be45-9aa22eba92e9 exists true
##[debug]bf184c95-f3f5-4dcf-be45-9aa22eba92e9 auth scheme = UsernamePassword
##[debug]adding password auth entry for feed http://xxxxxxxxxxx:8080/tfs/xxxxxxxxxxx/_packaging/xxxxxxxxx/nuget/v3/index.json
##[debug]Setting up sources
##[debug]selectOrConfig=config
##[debug]nugetConfigPath=C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]check path : C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]nugetConfigPath=C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]Absolute path for pathSegments: C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config = C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]build.sourcesDirectory=C:\Proyectos\Agent2\_work\1\s
##[debug]Absolute path for pathSegments: C:\Proyectos\Agent2\_work\1\s = C:\Proyectos\Agent2\_work\1\s
##[debug]nugetConfigPathpath supplied :true
##[debug]Agent.BuildDirectory=C:\Proyectos\Agent2\_work\1
##[debug]build.buildId=210
##[debug]No temp nuget.config auth
##[debug]ConfigFile: C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]Absolute path for pathSegments: C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe = C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe
##[debug]which 'C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe'
##[debug]found: 'C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe'
##[debug]which 'C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe'
##[debug]found: 'C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe'
##[debug]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe arg: restore
##[debug]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe arg: C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\xxxxxxxx\packages.config
##[debug]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe arg: -Verbosity
##[debug]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe arg: Detailed
##[debug]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe arg: -NonInteractive
##[debug]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe arg: -ConfigFile
##[debug]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe arg: C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]Agent.TempDirectory=C:\Proyectos\Agent2\_work\_temp
##[debug]NUGET_PLUGINS_CACHE_PATH set to C:\Proyectos\Agent2\_work\_temp\NuGetPluginsCache
##[debug]V2 credential provider set
##[debug]credProviderPath = C:\Proyectos\Agent2\_work\_tasks\NuGetCommand_333b11bd-d341-40d9-afcf-b32d5ce6f23b\2.153.2\CredentialProviderV2\plugins\netfx\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe
##[debug]Detected external credentials for:
##[debug]http://xxxxxxxx:8080/tfs/xxxxxxxx/_packaging/xxxxxxxx/nuget/v3/index.json
##[debug]agent.proxyurl=***
##[debug]agent.proxyusername=***
##[debug]agent.proxypassword=***
##[debug]Adding environment variable for NuGet proxy: http://***:***#yyyyyyyyyyy:8080/
##[debug]Agent.ProxyBypassList=***
##[debug]Getting sources from NuGet.config in this location: C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]Adding environment variable for NuGet proxy bypass: xxxxxxxx
##[debug]exec tool: C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe
##[debug]arguments:
##[debug] restore
##[debug] C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\xxxxxxxx\packages.config
##[debug] -Verbosity
##[debug] Detailed
##[debug] -NonInteractive
##[debug] -ConfigFile
##[debug] C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
[command]C:\Proyectos\Agent2\_work\_tool\NuGet\5.10.0\x64\nuget.exe restore C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\xxxxxxxx\packages.config -Verbosity Detailed -NonInteractive -ConfigFile C:\Proyectos\Agent2\_work\1\s\xxxxxxxx\NuGet.Config
##[debug]Re-evaluate condition on job cancellation for step: 'NuGet restore packages.config'.
##[error]The operation was canceled.
The task hangs and I must cancel it.
Could you help me to find what I missing or doing wrong?

I found the right process to get it working properly.
Install the agent.
Create a file named .proxybypass including the URLs to bypass the proxy in the agent directory:
I use the command echo *urltobypass* > .proxybypass
Configure the agent with proxy parameters configuration:
.\config.cmd --proxyurl *YourProxyUrl* --proxyusername *YourProxyUser* --proxypassword *YourProxyPassword*
With these steps to configure the agent the tasks execute properly.
Run a self-hosted agent behind a web proxy

Related

Azure CLI 2.x is not installed on this machine

I'm trying to upload blobs using "az storage blob upload-batch". I got below two exceptions.
##[error]Azure CLI 2.x is not installed on this machine.
##[error]Script failed with error: Error: Unable to locate executable file: 'pwsh'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
task: AzureCLI#2
displayName: 'Upload Files'
inputs:
azureSubscription: 'xxxxxxx'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$subscriptionName = $(az account show --query 'name' --output tsv)
az storage blob upload-batch `
--subscription $subscriptionName `
--account-name xxxxxxxxx `
--source "C:\xxx\yyy" `
--destination MyContainerName `
--auth-mode login
Thank you #N MZ , Posting your suggestion as an answer to help other community members.
##[error]Azure CLI 2.x is not installed on this machine.
##[error]Script failed with error: Error: Unable to locate executable file: 'pwsh'. Please verify either the file path exists or the file
can be found within a directory specified by the PATH environment
variable. Also verify the file has a valid extension for an executable
file.
For this above errors we need to install Azure cli
and check running cmd az version if its installed or not .
For More information please refer the below links:
MS DOC:Azure File Copy task
SO THREAD: How to run Azure CLI tasks from an Azure DevOps Pipeline
Microsoft Documentation
Although not the best approach, for a quick test, you could install az cli while running the job steps:
jobs:
- job: my_job
steps:
- script: curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
displayName: 'install az cli'

Env variable not being recognized

CICD: Azure devOps
Task: Azure CLI
Script Location: Inline Script
Task Version: 1
Agent: Self-hosted
Language: Go
I am facing a strange issue when I pass the env variable from Azure Pipeline.
Command (Inline Script):-
$env:ENV="FOO"
Output:-
2021-09-03T13:49:28.9213455Z
2021-09-03T13:49:28.9214265Z c:\Agent\_work\r1\a>$env:ENV="FOO"
**2021-09-03T13:49:28.9219788Z The filename, directory name, or volume label syntax is incorrect.**
2021-09-03T13:49:28.9298991Z ##[error]Script failed with error: Error: The process 'c:\Agent\_work\_temp\azureclitaskscript1630676963575.bat' failed with exit code 1
The same command works perfectly fine in local VM PowerShell but not sure why it doesn't from Pipeline. Any suggestions?
Note: Directory path is correct ONLY.
The script seems to be in .bat and $env:ENV=... is not a supported bat command.
$env:ENV="FOO"
This script is PowerShell Script.
You need to specify the use of PowerShell in the Azure CLI task to run the script.
In Azure CLI task V1 , it seems that there is no option to achieve this.
I suggest that you can use the Azure CLI task version 2:
- task: AzureCLI#2
displayName: 'Azure CLI '
inputs:
azureSubscription: xxx
scriptType: ps
scriptLocation: inlineScript
inlineScript: '$env:ENV="FOO"'

Error: Unable to locate executable file: 'powershell' when running Azure CLI task in ADO pipeline

I am trying to run an Azure CLI task in pipeline and getting the following error :
Starting: AzureCLI
==============================================================================
Task : Azure CLI
Description : Run Azure CLI commands against an Azure subscription in a PowerShell
Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
Version : 2.1.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
##[error]Script failed with error: Error: Unable to locate executable file: 'powershell'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
Finishing: AzureCLI
The pre-requisites mentioned in https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-cli?view=azure-devops is fulfilled.
**Pre-requisites mentioned in the ms site :**
Microsoft hosted agents have Azure CLI pre-installed. However if you are using private agents, install Azure CLI on the computer(s) that run the build and release agent. If an agent is already running on the machine on which the Azure CLI is installed, restart the agent to ensure all the relevant stage variables are updated.
I am not using any private agents. I am using a free subscription.
The task in pipeline yaml is as :
- task: AzureCLI#2
inputs:
azureSubscription: 'Free Trial(<My Subscription id>)'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: |
az --version
az account show
Why is the agent not able to find powershell in its system!!
Is this a bug?
Thanks!
I think you might be using a Linux agent such as 'ubuntu-latest'. Try changing it back to AzureCLI#2 and set scriptType: pscore. scriptType: ps doesn't work on Linux.
- task: AzureCLI#2
displayName: Azure CLI
inputs:
azureSubscription: 'sc-name'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az account show
Hi try without "scriptType" and change the CLI version to 1, Please see the below script,
- task: AzureCLI#1
inputs:
azureSubscription: 'Free Trial(<My Subscription id>)'
scriptLocation: 'inlineScript'
inlineScript: |
az --version
az account show

How to fix Azure-Powershell "hello world"-task that fails with error: Could not find the modules: 'Az.Accounts' with Version: '6.2.3'

I'm setting up an Azure devops pipeline in which I want to manipulate resources in my subscription. For this I try to use an AzurePowerShell task.
I trimmed down my attempts to a most basic hello world example that connects with my subscription:
pool:
vmImage: windows-2019
trigger: none
steps:
- task: AzurePowerShell#4
displayName: 'hello world'
inputs:
azureSubscription: 'azure-connection-dev'
azurePowerShellVersion: '6.2.3'
inline: |
Write-Output "Hello"
Write-Output "world"
When I trigger this pipeline I expect the pipeline to print "Hello world" but instead it fails with
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 4.157.4
Author : Microsoft Corporation
Help : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
##[error]Could not find the modules: 'Az.Accounts' with Version: '6.2.3'. If the module was recently installed, retry after restarting the Azure
What is wrong with the above hello world example?
The error message is unambiguously telling you the exact problem: The hosted agent doesn't have Az 6.2.3 on it. The available versions are documented. If you need a version that's not installed by default, you'll need to install it with Install-Module first.
The Azure Powershell task starts by logging in to your Azure subscription with the specified service connection. Since you're telling it to use an unavailable version, it's trying to load the module and immediately failing.

Azure DevOps, AppCenter Distribute fails for iOS native ap

I am trying to publish an IPA to App Center, the YAML for my build definition is the following :
# Xcode
# Build, test, and archive an Xcode workspace on macOS.
# Add steps that install certificates, test, sign, and distribute an app, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/xcode
pool:
vmImage: 'macOS-10.13'
trigger: none
variables:
- name: SDK
value: iphoneos
- name: Configuration
value: ReleasePPD
steps:
- task: DeleteFiles#1
inputs:
SourceFolder: '$(system.defaultWorkingDirectory)'
Contents: 'AuraApp.xcworkspace'
- task: CocoaPods#0
inputs:
forceRepoUpdate: false
displayName: 'pod install using the CocoaPods task'
- task: InstallAppleCertificate#2
inputs:
certSecureFile: 'ios_distribution.p12'
- task: InstallAppleProvisioningProfile#1
inputs:
provisioningProfileLocation: 'secureFiles' # Options: secureFiles, sourceRepository
provProfileSecureFile: 'Aura_PPD_Distribution_Profile.mobileprovision'
removeProfile: true
- task: Xcode#5
inputs:
xcWorkspacePath: '$(system.defaultWorkingDirectory)/AuraApp.xcworkspace'
actions: 'build'
sdk: $(SDK)
configuration: $(Configuration)
xcodeVersion: '10' # Options: 8, 9, 10, default, specifyPath
exportPath: '$(Build.ArtifactStagingDirectory)/PPD'
packageApp: true
#exportMethod: 'package'
exportOptions: 'auto'
#exportOptionsPlist: ''
scheme: 'Aura PPD'
signingOption: manual
signingIdentity: $(APPLE_CERTIFICATE_SIGNING_IDENTITY)
provisioningProfileUuid: $(APPLE_PROV_PROFILE_UUID)
- task: AppCenterDistribute#1
inputs:
serverEndpoint: 'Azure App Center'
appSlug: aurafoundation/Aura
appFile: $(Build.ArtifactStagingDirectory)/**/*.ipa
releaseNotesOption: 'input'
releaseNotesInput: 'Test'
The Xcode build task seems to be working well :
##[debug]exec tool: /usr/bin/xcodebuild
##[debug]arguments:
##[debug] -exportArchive
##[debug] -archivePath
##[debug] /Users/vsts/agent/2.146.0/work/1/s/Aura PPD.xcarchive
##[debug] -exportPath
##[debug] /Users/vsts/agent/2.146.0/work/1/a/PPD
##[debug] -exportOptionsPlist
##[debug] _XcodeTaskExportOptions.plist
[command]/usr/bin/xcodebuild -exportArchive -archivePath /Users/vsts/agent/2.146.0/work/1/s/Aura PPD.xcarchive -exportPath /Users/vsts/agent/2.146.0/work/1/a/PPD -exportOptionsPlist _XcodeTaskExportOptions.plist | /usr/local/lib/ruby/gems/2.6.0/bin/xcpretty --no-color
2019-02-12 11:03:58.404 xcodebuild[1595:20747] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path '/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Aura PPD_2019-02-12_11-03-58.402.xcdistributionlogs'.
▸ Export Succeeded
##[debug]success of first tool:true
##[debug]rc:0
##[debug]success:true
##[debug]task result: Succeeded
##[debug]Processed: ##vso[task.complete result=Succeeded;]Xcode task execution completed with no errors.
##[debug]Agent.Version=2.146.0
##[debug]Processed: ##vso[telemetry.publish area=TaskHub;feature=Xcode]{"xcodeVersionSelection":"10","actions":["build"],"packageApp":true,"xcodeVersion":"10.1","signingOption":"manual","exportOptions":"auto"}
##[section]Finishing: Xcode
The resulting IPA file shoud be located in /Users/vsts/agent/2.146.0/work/1/a/PPD according to the -exportPath parameter.
BUT ! The AppCenterDistribute step fails :
##[section]Starting: AppCenterDistribute
==============================================================================
Task : App Center Distribute
Description : Distribute app builds to testers and users via App Center
Version : 1.147.0
Author : Microsoft Corporation
Help : For help with this task, visit the Visual Studio App Center [support site](https://aka.ms/appcentersupport/).
==============================================================================
##[error]Error: Cannot find any file based on /Users/vsts/agent/2.146.0/work/1/a/**/*.ipa.
##[section]Finishing: AppCenterDistribute
So the question is : where is my .ipa located ? Why can't I find my .ipa in the exportPath ?
EDIT :
I changed the exportPath parameter to specify a full path : Users/vsts/agent/2.146.0/work/1/a/PPD/Aura.ipa
Now i get another error on the AppCenter Distribute task :
##[debug]found 1 paths
##[debug]applying include pattern
##[debug]1 matches
##[debug]1 final results
##[debug]....... selectedPaths: /Users/vsts/agent/2.146.0/work/1/s
##[debug]....... uniquePaths: /Users/vsts/agent/2.146.0/work/1/s
##[debug]-- Prepare symbols
##[debug]-- Prepare for uploading release.
##[debug]---- url: https://api.appcenter.ms/v0.1/apps/aurafoundation/Aura/release_uploads
##[debug]---- "{\"upload_id\":\"a349d7a0-10f2-0137-9dfa-12f79a9ee306\",\"upload_url\":\"https://rink.hockeyapp.net/api/sonoma/apps/a761af0d-7844-46a9-bf7b-701fa1db6b9c/app_versions/upload?upload_id=a349d7a0-10f2-0137-9dfa-12f79a9ee306\"}"
##[debug]---- http call status code: 201
##[debug]-- Uploading release...
##[debug]---- url: https://rink.hockeyapp.net/api/sonoma/apps/a761af0d-7844-46a9-bf7b-701fa1db6b9c/app_versions/upload?upload_id=a349d7a0-10f2-0137-9dfa-12f79a9ee306
##[debug]---- Failed with error: Error: form-data: EISDIR: illegal operation on a directory, read
##[debug]task result: Failed
##[error]Error: form-data: EISDIR: illegal operation on a directory, read
##[debug]Processed: ##vso[task.issue type=error;]Error: form-data: EISDIR: illegal operation on a directory, read
##[debug]Processed: ##vso[task.complete result=Failed;]Error: form-data: EISDIR: illegal operation on a directory, read
##[section]Finishing: AppCenterDistribute