3

I am trying to execute the few aws cmdlet command in post build script with TFS build. I have a AWS SDK tool is installed in build controller. I am able to run the same commands manually in Build controller. But when i invoke those commands in TFS post build script. It's giving me error that its not able to find the cmdlet installed on the build controller. I tried to change the execution policy but didn't help. I have an execution policy - bypass right now. script is executing but only the commands is not able to execute. I am thinking that it's issue because of something like Execution policy. Do we need to check anything else same like execution policy while we invoke any third party cmdlet from power shell.

Commands:

Set-AWSCredentials -AccessKey  -SecretKey 

Set-DefaultAWSRegion -Region us-east-1

Write-S3Object -BucketName agero-source-package -File "\\b tfadfa\adfa\adf\asdf\adsf\asdf\asd\xyz.zip"

Error:

Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' 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 \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:41 char:26
 + cd "\\b-tfsbc001wv\C$" | Set-DefaultAWSRegion -Region us-east-1
 +                          ~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo          : ObjectNotFound: (Set-DefaultAWSRegion:String) [], CommandNotFoundException
 + FullyQualifiedErrorId : CommandNotFoundException

 Write-S3Object : The term 'Write-S3Object' 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 \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:43 char:26
 + cd "\\b-tfsbc001wv\c$" | Write-S3Object -BucketName agero-source-package -File " ...
 +                          ~~~~~~~~~~~~~~
 + CategoryInfo          : ObjectNotFound: (Write-S3Object:String) [], CommandNotFoundException
 + FullyQualifiedErrorId : CommandNotFoundException
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
Meet101
  • 711
  • 4
  • 18
  • 35
  • Which version of TFS are you using? Is your PowerShell script that contains the commands running on build agent machine manually? I mean, try to logon your build agent (not controller) machine and run the script manually to check the result. – Cece Dong - MSFT Sep 08 '16 at 09:01

3 Answers3

1

From the error messages, it would appear that the AWSPowerShell module cannot be found/automatically loaded by whatever account the TFS build process is running as.

Check that the module is installed to a globally available location under which the version of PowerShell you have searches for modules or, that the path to the module folder is present in the $PSModulePath environment variable for the TFS build account.

Steve Roberts
  • 714
  • 4
  • 8
1

I got the same error on my TFS Build Agent:

Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' 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.

After I installed AWS Command Line Interface x64 bit (AWSCLI64) I was able to set the Set-DefaultAWSRegion by stepping over the line of code.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
0

I was getting this error until I ran Powershell using "Run as Administrator." So the problem might be with permissions.