Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Uploading the result of dotnet publish

Zörgő Zoltán November 3, 2023

Hi,
Spoiler: I am new to pipelines.
My yml looks like this:

image: mcr.microsoft.com/dotnet/sdk:8.0

pipelines:
default:
- step:
name: Publish to linux-arm
caches:
- dotnetcore
script:
- REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER}
- dotnet restore
- dotnet publish -r linux-arm -f net8.0 --self-contained true -p:PublishSingleFile=true
- step:
name: Put in downloads
deployment: test
script:
- pipe: atlassian/bitbucket-upload-file:0.6.0
variables:
BITBUCKET_ACCESS_TOKEN: $BITBUCKET_ACCESS_TOKEN
FILENAME: "/opt/atlassian/pipelines/agent/build/bin/Release/net8.0/linux-arm/publish"

The first step completes:

MSBuild version 17.8.0+6cdef4241 for .NET
Determining projects to restore...
Restored /opt/atlassian/pipelines/agent/build/LocalTestService.csproj (in 320 ms).
 LocalTestService -> /opt/atlassian/pipelines/agent/build/bin/Release/net8.0/linux-arm/LocalTestService.dll
LocalTestService -> /opt/atlassian/pipelines/agent/build/bin/Release/net8.0/linux-arm/publish/
However the second step fails because the location I copied from the first step log is not found:
File /opt/atlassian/pipelines/agent/build/bin/Release/net8.0/linux-arm/publish doesn't exist.

/opt/atlassian/pipelines/agent/build/bin/Release/net8.0/linux-arm/publish/* pattern does not help either.

1. What is the path I have to use to get it working?
2. Dotnet publish creates a folder with multiple files even with single file output. How can I zip them before uploading?

2 answers

1 accepted

0 votes
Answer accepted
Zörgő Zoltán November 5, 2023

I have it.

 

image: mcr.microsoft.com/dotnet/sdk:8.0

pipelines:
default:
- step:
name: Publish to linux-arm
caches:
- dotnetcore
script:
- REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER}
- dotnet restore
- dotnet publish -r linux-arm -f net8.0 --self-contained true -p:PublishSingleFile=true -o /var/tmp/publish/
- tar -czvf /var/tmp/playground.tar.gz /var/tmp/publish
- |
curl -X POST --url "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" \
--header "Authorization: Bearer ${BITBUCKET_ACCESS_TOKEN}" \
--form files=@"/var/tmp/playground.tar.gz"

Where BITBUCKET_ACCESS_TOKEN is a variable added to the pipeline containing a token generated for the repository.

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 7, 2023

Hi Zörgő!

I see that you figured out a workaround, I just wanted to give you some context on why you were seeing this error and a way to use two steps:

Every step of a pipelines build runs in a separate Docker container. For every step of your build, a Docker container starts (the build container) using the image you have specified in your bitbucket-pipelines.yml file. The repo is cloned in the build container, and then the commands of the step's script are executed. When the step finishes that Docker container gets destroyed.

If you want to use in a step a file that was generated during a previous step, you will need to specify this file as an artifact:

Please keep in mind that only files that are in the BITBUCKET_CLONE_DIR (/opt/atlassian/pipelines/agent/build) at the end of a step can be configured as artifacts. Artifact paths are relative to the BITBUCKET_CLONE_DIR.

If you want to use two steps and if the artifacts are generated in the path bin/Release/net8.0/linux-arm/publish/ inside the clone dir, you can adjust the yml file from your first post as follows:

image: mcr.microsoft.com/dotnet/sdk:8.0

pipelines:
default:
- step:
name: Publish to linux-arm
caches:
- dotnetcore
script:
- REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER}
- dotnet restore
- dotnet publish -r linux-arm -f net8.0 --self-contained true -p:PublishSingleFile=true
artifacts:
- bin/Release/net8.0/linux-arm/publish/**
- step:
name: Put in downloads
deployment: test
script:
- pipe: atlassian/bitbucket-upload-file:0.6.0
variables:
BITBUCKET_ACCESS_TOKEN: $BITBUCKET_ACCESS_TOKEN
FILENAME: "bin/Release/net8.0/linux-arm/publish/**"

You can also adjust the same way the latest version of your yml file that uses a zip file, but the zip needs to exist inside the clone dir or a subdirectory in order to define it as an artifact and use the pipe.

Please feel free to reach out if you have any questions!

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events