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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,465,872
Community Members
 
Community Events
176
Community Groups

Request: Windows SSH support, parse command without `bash -c`

Hey, I use OpenSSH on Windows Server and couldn't get ssh-run to work, mainly because it doesn't allow anything but bash commands. I would like to propose another MODE that just takes the command argument and parses that without the `bash -c` bit.


elif [[ ${MODE} = "windows" ]]; then
info "Executing ${MODE} on ${SERVER}"
run ssh -A -tt -i ~/.ssh/pipelines_id -o 'StrictHostKeyChecking=no' -p ${PORT:-22} ${EXTRA_ARGS} $SSH_USER@$SERVER ${ENV_VARS} "$COMMAND"

 (The `-tt` bit might have to be removed)

I've stolen some of the ssh-run pipe code to manually connect to the Windows Server 2016 via SSH and run commands on it from the pipeline.

For example, here is some yaml to first stop Windows services and IIS websites and then run Robocopy on Windows that in this case makes some backups for me before I deploy new code to the server:


- step:
name: Stop services and IIS sites
script:
# Below commands create necessary files for manual ssh to WEB2
- mkdir -p ~/.ssh
- cp /opt/atlassian/pipelines/agent/ssh/id_rsa_tmp ~/.ssh/pipelines_id
- cat /opt/atlassian/pipelines/agent/ssh/known_hosts >> ~/.ssh/known_hosts
- chmod -R go-rwx ~/.ssh/
# Execute stop services and stop website commands on WEB2 via ssh
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com net stop "SITEDev2TenantService"
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com net stop '"SITE Dev2 SMS Service"'
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com C:/Windows/System32/inetsrv/appcmd stop site SITEDev2
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com C:/Windows/System32/inetsrv/appcmd stop site SITEDev2API

 

- step:
name: Backup existing files
script:
# Below commands create necessary files for manual ssh to WEB2
- mkdir -p ~/.ssh
- cp /opt/atlassian/pipelines/agent/ssh/id_rsa_tmp ~/.ssh/pipelines_id
- cat /opt/atlassian/pipelines/agent/ssh/known_hosts >> ~/.ssh/known_hosts
- chmod -R go-rwx ~/.ssh/
# Copy site files using robocopy to back them up
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com 'robocopy E:/Sites/SITEDev2 E:/_backups/SITEDev2 /E /purge /NJS & if %errorlevel% leq 4 exit 0'
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com 'robocopy E:/Sites/SITEDev2API E:/_backups/SITEDev2API /E /purge /NJS & if %errorlevel% leq 4 exit 0'
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com 'robocopy E:/Services/SITEDev2TenantService E:/_backups/SITEDev2TenantService /E /purge /NJS & if %errorlevel% leq 4 exit 0'
- ssh -A -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 $WEB2_USER@MYSERVER.com 'robocopy E:/Services/SITEDev2SMSService E:/_backups/SITEDev2SMSService /E /purge /NJS & if %errorlevel% leq 4 exit 0'

 

Notice lack of `-tt` parameter in SSH calls, as this was causing me a lot of trouble, only the first command would successfully run, even though the bitbucket pipeline didn't stop. Removing `-tt` allowed to run multiple commands without issues. Robocopy also has additional parameters passed as due to the way Robocopy works, it has to be forced sometimes to return a correct success code.

Nevertheless, this MODE could be implemented in the pipe, which would make it much easier for the Windows Server users to run commands over SSH from bitbucket pipelines.

1 answer

@kamilkloc  hi. It's a good idea to create feature request:

list of requested features 

Regards, Igor

Hi, pls can you repost the link as it doesn't work :(
Also, I could potentially fork the repo, try and build it, test it and do a pull request if that's something that you guys are happy to review and potentially merge into main repo?

@kamilkloc thanks. I updated the link in my reply

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events