How to save artifacts in Bitbucket-Pipelines

后端 未结 3 1108
我寻月下人不归
我寻月下人不归 2021-02-14 12:48

I am new to bamboo. What I try to do is collecting all .dacpac files that are created during the build process.

image: microsoft/dotnet:latest
pipe         


        
相关标签:
3条回答
  • 2021-02-14 13:32

    Unfortunately according to the documentation all artifacts are deleted after the pipeline run:

    https://confluence.atlassian.com/bitbucket/using-artifacts-in-steps-935389074.html

    "Once a pipeline completes, whether it succeeds or fails, the artifacts are deleted."

    However you can deploy artifacts to the Bitbucket downloads section, or anywhere else:

    https://confluence.atlassian.com/bitbucket/deploy-build-artifacts-to-bitbucket-downloads-872124574.html

    - step:
        name: Archive
        script:
          - curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"something/**"
    
    0 讨论(0)
  • 2021-02-14 13:32

    I think one good alternative is to use the bitbuckets download section like previously mentioned, however you can use their dedicated tool instead of using curl and hopping the API will not change and break your pipeline.

    https://support.atlassian.com/bitbucket-cloud/docs/deploy-build-artifacts-to-bitbucket-downloads/

    Compared to curl I think it's safer, easier to setup and easier to maintain. For example, the linked documentation shows 0.1.2 version of the tool, while the newest is 0.3.2, it required me to only update that version number and nothing else to stay up to date. I had to setup app permission key with the write access to my repositories, setup this as pipeline variable, setup my account name as a pipeline variable (the linked documentation described it pretty well) and then add a simple step to my pipeline yaml file. One disadvantage I can think of is that for bigger files curl might be better. So take it as yet another way of doing things, not as the ultimate way of doing everything.

    My example yaml, you use some container to build your sources, it, you have your Makefile build step defined, then I rename my output artifact file and postfix a build ID (this way I will have multiple output files in my download section, not just the latest). Then I will make sure the next step will have access to these artifacts by adding the artifacts in the build step:

    artifacts:

    • build/output-*.zip

    And then the last deploy step will have access to the zip and will upload it for you, their tool doesn't need anything else just 3 variables setup, user name, app key and the file to upload.

    For completion the example pipeline yaml:

    image: <SOMETHING>
    
    pipelines:
      default:
        - step:
            name: 'Build'
            script:
              - make all
              - mv build/output.zip build/output-$BITBUCKET_BUILD_NUMBER.zip
            artifacts:
              - build/output-*.zip
    
        - step:
            name: 'Deploy the output into the download section'
            script:
              - pipe: atlassian/bitbucket-upload-file:0.3.2
                variables:
                  BITBUCKET_USERNAME: $BITBUCKET_USERNAME
                  BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
                  FILENAME: "build/output-$BITBUCKET_BUILD_NUMBER.zip"
    
    0 讨论(0)
  • 2021-02-14 13:44

    In bitbucket-pipelines.yml, whenever you progress to a different "step:", it will reset almost everything and behave independently to a previous step. This is not always obvious, and can be confusing.

    In your previous step, you moved into a sub-folder using cd BackgroundCode. When the script progresses to the "artifacts:" step, the current working directory will reset back to its original $BITBUCKET_CLONE_DIR. So you need to cd BackgroundCode again in each step or use a path that's relative to the $BITBUCKET_CLONE_DIR, like this:

    artifacts:
     - BackgroundCode/**/*.dacpac
    

    or

    step2:
     - cd BackgroundCode
     # List the files relative to the 'BackgroundCode' directory
     - find . -iname '*.dacpac'
    

    This will now save the artifact automatically (for 7 days), and you can see it in the "Artifacts" tab at the top.

    0 讨论(0)
提交回复
热议问题