Bamboo deploy using Powershell script - powershell

When trying to Deploy IIS content files using powershell, I am seeing the following error:
Failing task since return code of [powershell -ExecutionPolicy bypass
-Command /bin/sh file.ps1
We are trying to deliver web content (several web service folders) and a set of associated web.config files to an IIS server using a powershell scrpt. The script and config files are stored in SCM (Stash) and pulled across as part of a checkout task in Bamboo which are then published as artifacts to the bamboo deploy job.
The deploy job is failing.
Does anyone know the correct way to set this up both in the Bamboo Deploy job or on the Windows Server?
Many thanks in advance.

For anyone trying to resolve this issue in future, I resolved this issue by installing a Bamboo agent onto the Windows Server.
This means that the powershell script gets checked out onto the Windows server as part of the deploy job (using the Sourcecode checkout task) and so can then be run as powershell rather than the Bamboo local agent which is running on a Linux box trying to run the powershell script as a linux shell.
The only other issue that had to be overcome was ssl certs needed to be installed into the JKS (cacerts) file on the Windows Server (where the remote agent is running) as we have Bamboo running over https.

Related

Service Fabric/Jenkins integration issue

I am trying to automate deployment to Azure Service Fabric with Jenkins and ServiceFabric PowerShell extension. Jenkins ServiceFabric plugin is not a good option in my case due to lack of control and flexibility over deployment process.
I've faced following issue - Jenkins can't recognize SF PowerShell cmdlets
Connect-ServiceFabricCluster : The term 'Connect-ServiceFabricCluster'
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
ServiceFabric setup is correct because tt works like a charm when I run the script locally from PowerShell.
So, I've tried to run Jenkins locally instead of service mode as suggested in different posts over the internet, but this haven't resolved the issue.
The other things i've tried:
run the script with self-elevation to admin
run x86/x64 powershell modes
run the script via calling PowerShell exe from cmd runner instead
powershell plugin
forcing "unrestricted" mode
double-dot before script name
I'm still receiving the same result.
So, I tried ServiceFabric Python Cli as an alternative, but faced the other issue - it returns "Bad SSL handshake" on "sfctl cluster select" with certificate, which worked with PS ServiceFabric cmdlets locally
Any ideas?
This is similar to Azure/service-fabric-issues issue 491 which was about a mismatch between the Azure Service Fabric SDK and the Service Fabric runtime.
For instance:
The 2.7 SDK will work against a version 6.0 cluster, but the task will not work on with the 2.8 SDK installed on the agent.
Plus:
Service Fabric PowerShell cmdlets requires PowerShell 3.0 or higher.
Service Fabric uses Windows PowerShell scripts for creating a local development cluster and for deploying applications from Visual Studio. By default, Windows blocks these scripts from running.
To enable them, you must modify your PowerShell execution policy. Open PowerShell as an administrator and enter the following command:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force -Scope CurrentUser
So: if that script is working locally, but not through a Jenkins job on a Jenkins agent, look for differences between the local execution environment (where it is working) and the Jenkins one (where it fails).
The user might not be the same and/or the runtime version might not be compatible with the SDK version.
Do you have Jeknis PowerShell Plugin installed in your system ??
if so can you add your commands into the Power Shell dialog box and see if it works :)

Run powershell build step in VSTS agent installed on mac?

I installed VSTS build agent on mac to build xamarin iOS project. Builds worked fine until I added powershell build step.
Even though I installed powershell for mac (https://github.com/PowerShell/PowerShell) and re-installed the agent, VSTS complains it does not have agent that is capable to run the build.
No agent could be found with the following capabilities:
DotNetFramework, Xamarin.iOS, npm
When I disable the build step, builds work just fine.
Is it possible to run powershell build step on Mac?
As MrHinsh clarified, the PowerShell task cannot be used on Mac.
As a workaround I used ShellScript task:
With the following bash script:
#!/bin/bash
powershell ./SetAppVersion.ps1
Also, the powershell installer did not seem to add powershell to my PATH so I had to add it:
$ export PATH=$PATH:/usr/local/microsoft/powershell/6.0.0-alpha.16
If you're sure that DotNetFramework is installed then you can go to the Agent Queues settings and add a custom Capability to it called exactly that.
That should allow it to run but it might fail after that if the agent can't actually find them, but it might also succeed so it's probably worth a try.
No, you can't use a PowerShell task on a Mac, only node tasks are supported.
PowerShell tasks as currently written in PowerShell3 which is not supported on Mac. You can request that the team implement this on http://visualstudio.uservoice.com
In TFS build go to Agents Queues=>Capablilities=>Add variable named as DotNetFramework and give value for mac agent's dotnet framework path.
It's fix for the issue "No agent could be found with the following capabilities:DotNetFramework"
This is a follow-up to the accepted answer to address a question in a comment which I also had.
Thanks to spatialguy for posting and finding a simple solution to this problem. I had the same problem as KeithA45:
QUESTION: What if you wanted to do the same, but also pass arguments to the Bash script which passes them to the Powershell script?
I found a solution to this, first off, I modified the shell script task to include the Visual Studio Team Services (VSTS) environmental variables that I wanted to pass to the powershell script.
Next, I pass the arguments through to the called powershell script by slightly modifying the shell script mentioned by the accepted answer.
#!/bin/bash
powershell ./Version.ps1 $1 $2
Finally, in the powershell script, I catch the arguments that have been passed through using using param like this:
param([string]$version, [string]$path)
Wherein I can now use the variables $version and $path which contain the original arguments entered in VSTS to the needs of my powershell script.
Things seem to have moved forward because I ran successfully today a PowerShell#2 task on a Mac Self-Hosted Agent from an Azure DevOps build pipeline.
By checking "Enable system diagnostics" when queuing the build, the log shows me that the task found itself the path to the PowerShell Core (pwsh) that I installed on my Mac with the help of Homebrew (brew cask install powershell - see https://learn.microsoft.com/fr-fr/powershell/scripting/install/installing-powershell-core-on-macos).

TeamCity with npm - Error: ENOENT, stat 'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm'

I'm having serious problems getting the last pieces of my TeamCity configuration in place.
I have a powershell step that executes the following commands:
& npm install
& grunt build
logging the following output:
Build (Powershell) (1s)
[13:18:08]PowerShell Executable: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
[13:18:08]Working directory: C:\BuildAgent\work\6a434ee5d01fd0d9
[13:18:08]PowerShell arguments: [-NonInteractive, -ExecutionPolicy, ByPass, -File, C:\BuildAgent\temp\buildTmp\powershell8407335260182621582.ps1]
[13:18:09]Error: ENOENT, stat 'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm'
[13:18:09]
[13:18:09]grunt-cli: The grunt command line interface. (v0.1.13)
[13:18:09]Process exited with code 0
I've seen that this is a known problem, but none of the solutions has worked for me so far.
My setup is the following: I have two virtual machines in Azure, build and agent. Both are connected to the same AD domain, domain, in which there is a user domain\teamcityuser, who is of "standard" class (i.e. not admin). This user runs both the build server (on the build instance) and the build agent (on the agent instance).
I've tried these things without success:
Creating the directory in the error message, making sure that domain\teamcityuser has full controll access rights to it.
Creating an npm directory under C:\Users\teamcityuser\AppData\Roaming
Creating a file C:\Windows\System32\config\SystemProfile\.npmrc with the contents prefix=C:\npm-global, as well as creating the latter folder
Running npm cache clean before running the build
Installing a global npm package through npm install -g npm
What more can I try to get this working?
And to avoid the XY problem, here's my actual problem:
I have a .NET Web API project with CI setup through this TeamCity installation, via Octopus Deploy and to the hosting server. I also have a github repo with the code for a web SPA that will consume the API. The spa is built with grunt build, after which there's a dist folder with everything I need to deploy.
I'd like to re-use as much as possible of the CI architecture to roll out the client too.
Given that path to executable contains SysWOW64, this is an x32 Powershell, therefore, it refers to x32 system profile path, which is located at C:\Windows\sysWOW64\config\systemprofile. So, you need to use that path as your base in order to implement any workarounds, say, create C:\Windows\sysWOW64\config\systemprofile\AppData\Roaming\npm folder, and not plain C:\Windows\system32\config\systemprofile\AppData\Roaming\npm.

Run Powershell script on TFS server for publish to Azure

I try to configure TFS for Continuous Delivery to Azure by this article
In article TFS published package to Azure with Powershell script.
When build starts I get errors like ObjectNotFound: (Set-AzureDeployment:String) [], CommandNotFoundException. Looks like I didn't install Azure cmdlets, but I install all from Web Platform Installer.
And when I try to run script locally on server - it works and deploys package.
In article Powershell starts by adding InvokeProcess to template with Filename="PowerShell".
I think I just don't run Powreshell correctly.
Maybe somebody has some ideas which command should I use?
Find a solution
Powershell cann't find Azure module.
Add this before Import-Module Azure command in script
$env:PSModulePath=$env:PSModulePath+";"+"C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell"
Could be that you installed the cmdlets on the user profile. Try re-install after logging in with the account running the build service.

Start test by cc.net on remote machine

folks!
I am a newbie for cc.net tool. And i have got problem.I use a chain c#+webdriver for chrome + nunit (2.6) + cc.net ( 1.6.7981.1).I want run my test tasks on remote machine (no cc.net server machine).I have investigated this issue, but didnt found clear answer about distributed launching webdriver tests.
Is it possible for current cc.net?
i resolved issue by next way:
I shared a folder on remote machine and include in cc.net config a few tasks.
Task for copying a code to remote machine (xcopy)
Task for launch psexec which start bat file on remote machine
bat file includes 2 commands:
run msbuild
run nunit-console
After test work cc.net catch testresult file and send mail.