user6269864
user6269864

Reputation:

How to build a subfolder in Bitbucket Pipelines

I am struggling to configure the build in Bitbucket Pipelines.

It's a C# solution and the code is located in a subfolder, rather than in the root folder of the repository. This is why when I build it, I get the error:

+ dotnet restore

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

I've read the docs but there seems to be no option to try to specify a subfolder. How do you configure it then?

Here's my .yml file:

image: microsoft/dotnet:latest

pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script: # Modify the commands below to build your repository.
          - export PROJECT_NAME=MyProjectNameHere
          - export TEST_NAME=MyProjectNameHere
          - dotnet restore
          - dotnet build $PROJECT_NAME
          - dotnet test $TEST_NAME

Upvotes: 7

Views: 6056

Answers (4)

İsmail Kocacan
İsmail Kocacan

Reputation: 1234

I found it by experiment.

image: mcr.microsoft.com/dotnet/core/sdk:3.1
pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script: # Modify the commands below to build your repository.
          - cd MainDir
          - cd SubDir
          - export PROJECT_NAME=MyProject
          - export TEST_NAME=MyProject.Test
          - dotnet restore 
          - dotnet build $PROJECT_NAME
          - dotnet test $TEST_NAME

Upvotes: 0

Mr-IDE
Mr-IDE

Reputation: 7651

Maybe you could cd into the subfolder before calling the build commands.

image: microsoft/dotnet:latest

pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script:
          - cd MyProject # Set current working directory to subfolder
          - export ...
          - dotnet restore

You could also add checks to print the current folder at any time, with a step that runs pwd ("print working directory").

Upvotes: 3

Fjut
Fjut

Reputation: 1324

Now you can also use the project folders and do not need to use the .sln file in the PROJECT_NAME and TEST_NAME variables.

- step:
    caches:
      - dotnetcore
    script: # Modify the commands below to build your repository.
      - export PROJECT_NAME=YourSolutionFolder/YourProjectFolder
      - export TEST_NAME=YourSolutionFolder/YourTestProjectFolder
      - dotnet restore YourSolutionFolder
      - dotnet build $PROJECT_NAME
      - dotnet test $TEST_NAME

Upvotes: 0

user6269864
user6269864

Reputation:

Found it by experiment, the docs didn't mention it at all.

You need to use full path and solution filename on two lines and only the folder name on the restore line:

image: microsoft/dotnet:latest

pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script: # Modify the commands below to build your repository.
          - export PROJECT_NAME=FolderNameHere/MySolution.sln # use the full path and solution file name
          - export TEST_NAME=FolderNameHere/MySolution.sln # use the full path and solution file name
          - dotnet restore FolderNameHere # use only folder name here
          - dotnet build $PROJECT_NAME
          - dotnet test $TEST_NAME

Upvotes: 6

Related Questions