Bitbucket管道通过ssh远程运行windows bat(批处理)文件

问题描述 投票:0回答:1

Bitbucket Pipelines
一起玩。

我使用

scp
将目录复制到远程服务器,效果非常好

- step:
        name: Deploy to server
        deployment: staging
        script:
            - pipe: atlassian/scp-deploy:0.3.9
              variables: 
                USER: Administrator
                SERVER: 145.131.29.64
                REMOTE_PATH: C:\Websites\dev.api.lekkerparkeren.nl
                LOCAL_PATH: 'release'
                DEBUG: 'true'

但现在我需要在远程主机上执行一个bat(批处理)文件来停止IIS、复制目录并再次启动IIS。 但是我如何通过 Bitbucket 管道来做到这一点。

我尝试过使用

atlassian/ssh-run:0.4.1
,但这没有任何作用

        - step:
        name: Install on server
        script:
            - pipe: atlassian/ssh-run:0.4.1
              variables: 
                SSH_USER: Administrator
                SERVER: 145.131.29.64
                MODE: 'script'
                DEBUG: 'true'
                COMMAND: 'C:\Websites\mywebsite.com\release\deploy.bat'
docker github continuous-integration bitbucket bitbucket-pipelines
1个回答
0
投票

我来晚了几个月,但我刚刚遇到了同样的问题,也许我的解决方案可以帮助其他人。

事实是,我认为您无法使用该管道执行批处理文件(至少我不能)。我发现很多人建议建造自己的管道,但这是我作为最后手段而留下的。

我最终做的是:

  1. 通过 WSL 在我的 Windows 服务器上安装 Linux 发行版。 (这一点我不是 100% 确定,因为我在安装 Ubuntu 后才尝试了接下来的两个步骤)
  2. 将我的 .bat 文件更新为 .ps1。
  3. 然后更新
    bitbucket-pipeline.yml
    以执行该 .ps1 文件。

有很多关于如何执行第一步的文档,所以我不会在这里记录,我将分享我在其他两步中所做的事情。

将 .bat 文件更新为 .ps1

在您的情况下,新文件名将是

C:\Websites\mywebsite.com\release\deploy.ps1

内容是这样的

Stop-WebAppPool -Name {your app pool name}
robocopy C:\Websites\dev.api.lekkerparkeren.nl {your destination path} /s /z /zb /r:5 /w:5 /np
Start-WebAppPool -Name {your app pool name}

您可以在robocopy官方文档中找到标志的含义并随意更改。

更新 bitbucket-pipeline.yml

- step:
        name: Install on server
        script:
            - pipe: atlassian/ssh-run:0.6.0
              variables: 
                SSH_USER: Administrator
                SERVER: 145.131.29.64
                DEBUG: 'true'
                COMMAND: 'powershell.exe -FILE C:/Websites/mywebsite.com/release/deploy.ps1'

默认模式是command,该命令将在windows powershell上执行ps1。如果调试正在工作并且您不需要它,您可以删除它。

我还建议对用户和服务器使用 Bitbucket 变量,但这取决于你。

© www.soinside.com 2019 - 2024. All rights reserved.