6

I am trying to use new tool pipelines from bitbucket. I have multiple .NET console application (not Core app) than i want to build and download. I found this page that says that I can use mono to build my project. I use this .yml file to build it.

image: mono

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

Build was successful but now I am stuck with downloading my app (exe with all dlls). I found here that I can use bitbucket downloads. But how to download my deploy folder? Here I found that I can zip some files and then put it to bitbucket downloads. But how I can use this with mono, and how I can zip a whole folder, and then download it? I don't mind to use something else like mono.

peterh
  • 11,875
  • 18
  • 85
  • 108
Pavol
  • 552
  • 8
  • 19

2 Answers2

2

Mono is built on debian:wheezy, any linux commands you run in the script portion of the YML file can help you extract the file before BitBucket Pipelines pulls down the container. In the example you included there is a POST command at the end which deploys the artefact to Downloads in Bitbucket.

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

It explains the environment variables $BB_ACCESS further down, others are loaded in at runtime for you.

You'll need to find the file path mono compiles to and adjust the example's code to push to Bitbucket Downloads, or Amazon s3 is a good option too.

timmah.faase
  • 2,219
  • 1
  • 15
  • 23
2

A bit late for this answer...

Firstly, use msbuild instead of xbuild as xbuild is deprecated.

Now, what you want is a successful build as well push the release to bitbucket downloads.

Here is how you do it:

1. Create an App password for the repository owner

Log in to Bitbucket as the repository owner (also the user who will upload the files) and go to Bitbucket Settings > App Passwords.

Create a new app password with write permissions to your repositories, and take note of the generated password that pops up. The name of the password is only for your reference, so use "Pipelines" or any other name you like.

App Password

You should now have two values that you will need for the next step.

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

2. Create a Pipelines environment variable with the authentication token

Define a new secure environment variable in your Pipelines settings:

  • Parameter name: BB_AUTH_STRING
  • Parameter value: <username>:<password> (using the values from step 1)

You can define this environment variable either in the repository settings, or in the settings for the account that owns the repository.

The example below shows the settings for an individual account environment variable, where the repository is owned by an individual. (Note that in the case where a team owns the repository, you must configure environment variables in the team settings for them to be visible in Pipelines.)

enter image description here

3. Enable your Pipeline to deploy your artifacts using curl and the Bitbucket REST API

First add line to zip your release dir:

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

It may be possible that the pipeline bash does not have zip installed. To install zip, add the following lines to your pipeline before the above command:

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

Now finally add the curl command that uses Bitbucket REST API:

- 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"

If you wish, you can remove the unneeded release zip file from the bin dir as the zip is now already in Bitbucket downloads:

- rm -f bin/Release.zip

Here is the full 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

Note that your release directory may differ from the sample above

Samar Rizvi
  • 423
  • 5
  • 18