首页 文章

Bitbucket管道.net部署

提问于
浏览
3

嗨伙计们,我正在尝试使用bitbucket的新工具管道 . 我有多个.NET控制台应用程序(不是核心应用程序),而不是我想要构建和下载 . 我发现这个page表示我可以使用mono来构建我的项目 . 我使用这个.yml文件来构建它 .

image: mono

pipelines:
  default:
    - step:
        script:
          - nuget restore
          - MONO_IOMAP=case xbuild /t:Build /p:Configuration="Release" /p:Platform="Any CPU" Solution.sln

构建成功但现在我不得不下载我的应用程序(exe与所有dll) . 我发现here我可以使用bitbucket下载 . 但是如何下载我的部署文件夹? Here我发现我可以压缩一些文件,然后把它放到bitbucket下载 . 但我如何使用单声道和我如何拉链整个文件夹,然后下载它?...我不介意使用像mono这样的东西 . 谢谢你的任何建议:)

2 回答

  • 0

    Monobuilt on debian:wheezy ,您在YML文件的脚本部分中运行的任何linux命令都可以帮助您在BitBucket管道拉下容器之前提取文件 . In the example you included最后有一个POST命令,它将artefact部署到Bitbucket中的Downloads .

    curl -v -u $BB_ACCESS -X POST https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/downloads/ -F files=@aqua_lambda.zip
    

    它为您解释了环境变量 $BB_ACCESS 更低,others are loaded in at runtime .

    你'll need to find the file path mono compiles to and adjust the example'代码推送到Bitbucket下载,或Amazon s3也是一个不错的选择 .

  • 2

    这个答案有点晚了......

    首先,使用 msbuild 而不是xbuild,因为不推荐使用xbuild .

    现在,你想要的是一个成功的构建,并将发布推送到bitbucket下载 .

    Here is how you do it:

    1.为存储库所有者创建应用程序密码

    以存储库所有者(也是将上载文件的用户)登录Bitbucket并转到Bitbucket Settings > App Passwords .

    使用 write permissions 为您的 repositories 创建一个新的应用密码,并记下弹出的生成密码 . 密码的名称仅供您参考,因此请使用"Pipelines"或您喜欢的任何其他名称 .

    App Password

    您现在应该具有下一步所需的两个值 .

    <username>: Bitbucket username of the repository owner (and also the user who will upload the artifacts)
    <password>: App password as generated by bitbucket
    

    2.使用身份验证令牌创建管道环境变量

    在管道设置中定义新的安全环境变量:

    • 参数名称: BB_AUTH_STRING

    • 参数值: <username>:<password> (使用步骤1中的值)

    您可以在存储库设置中或在拥有存储库的帐户的设置中定义此环境变量 .

    下面的示例显示了单个帐户环境变量的设置,其中存储库由个人拥有 . (请注意,在团队拥有存储库的情况下,您必须在团队设置中配置环境变量,以使它们在管道中可见 . )

    enter image description here

    3.使您的Pipeline能够使用curl和Bitbucket REST API部署工件

    首先添加一行来压缩你的发布目录:

    - zip -j bin/Release.zip bin/Release/
    

    管道bash可能没有安装zip . 要安装zip,请在上述命令之前将以下行添加到管道中:

    - apt-get update
    - apt-get -y install zip
    

    现在最后添加使用Bitbucket REST API的curl命令:

    - curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"bin/Release.zip"
    

    如果您愿意,可以从bin目录中删除不需要的版本zip文件,因为zip现在已经在Bitbucket下载中:

    - rm -f bin/Release.zip
    

    这是完整的pipeline.yml:

    image: mono
    
    pipelines:
      default:
        - step:
            script:
              - nuget restore
              - MONO_IOMAP=case msbuild /p:Configuration="Release" /p:Platform="AnyCPU" Solution.sln
              - apt-get update
              - apt-get -y install zip
              - zip -r bin/Release.zip bin/Release/
              - curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"bin/Release.zip"
              - rm -f bin/Release.zip
    

    请注意,您的发布目录可能与上面的示例不同

相关问题