Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Pipe to connect to Powershell

Has anyone been able to connect to powershell via bitbucket pipelines? I have some simple SharePoint code that I house in my bitbucket repo and would like to start deploying those updates via pipelines.

I'm unable to find any documentation on this and was wondering if anyone else has had any experience doing this.  

Not much here, but this is what I have so far...

definitions:
services:
docker:
memory: 2048
steps:
- step: &connect-to-powershell
name: Connect to Powershell
image: mcr.microsoft.com/powershell
script:
- CMD [ "Connect-SPOService", "-Url", $psURL ]

pipelines:
branches:
master:
- step: *connect-to-powershell

 ...and this is the error message I recieve.

+ CMD [ "Connect-SPOService", "-Url", $psURL ]
bash: CMD: command not found

 Any help or guidance here would be greatly apprecaited.

 

Thank you!

1 answer

@John Issa you can see 'bash' in error log.

It means by default pipeline supports bash commands.

But you can try execute in a script  powershell commands you need via pwsh tool.

For example:

step:
name: powershell
image: mcr.microsoft.com/powershell
script:
- pwsh -Command {Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable}

 

Also, looks like powershell does not have sharepoint installed. You can do something for this.

If you don't succeed with that, you can try going with Custom pipe. Look how you can create your custom pipe here . Because I see, that executing this just in pipeline seems quite complex.

Regards, Galyna

... or a little easier on the eyes + multiline support. 

name: Gotta have pwsh
image: mcr.microsoft.com/powershell
script:
- >-
pwsh -Command "& {
Write-Host 'Hello Powershell'
}"
Like Dmytro Shchepak likes this

@Galyna Zholtkevych @Cronje van Heerden 

Could you please suggest how to execute pwsh command on the remote server?
Want to:
- make a backup,
- stop IIS,
- copy a new site,
- launch IIS.

I'll be appreciated for any help.

I have tried a few ways but still can't solve how to do this.

 

#2nd step to deploy to server

- step:

name: Deploy to server

deployment: staging

script:

- pipe: atlassian/scp-deploy:1.1.0

variables:

USER: 'deploy' # $USER

SERVER: '1.1.1.1' # $SERVER

REMOTE_PATH: 'D:/ttt/' # $REMOTE_PATH

LOCAL_PATH: 'release/*'

# DEBUG: 'true'

EXTRA_ARGS: ["-P", "8022"] #port

#3rd step runs script on server

- step:

#name: powershell

image: mcr.microsoft.com/powershell

script:

- pwsh -Command {Enter-PSSession -HostName '1.1.1.1' -UserName 'deploy'}

- pwsh -Command {Invoke-Command -ComputerName '1.1.1.1' -ScriptBlock {Get-UICulture}}

- pwsh -Command {cmd /c ver}

- pwsh -Command {Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable}

- pwsh -Command {Copy-Item -Path "c:\inetpub\GS 2.0_SM" -Destination "d:\ttt\site backup\*" -Recurse}

I haven't considered that use case before .. my guess would be that the permissions and port forwarding requirements for remote Powershell would be a problem if you're running this from Atlassian Cloud build runners.

If it's an option to run docker containers on the target server I'd try running a self-hosted build runner on the target server with a volume mapped to the target IIS folder only. 

Thanks for the so fast answer.

We don't use Docker, maybe it'll be in the future.

Previously I sought to try to use some batch script but PowerShell looks smarter.

Maybe it has sense make some research http://techdiksha.com/run-powershell-scripts-remote-machine-azure-release-pipeline/ , I hope it can help reach the aim.
I'll try to look.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

495 views 16 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you