如何将正确的项目路径传递给 bitbucket 管道?

How to pass the correct project path to bitbucket pipeline?

我想使用 bit bucket pipeline

部署 aws lamda .net core project

我创建了如下所示的 bitbucket-pipelines.yml 但是在构建 运行 之后出现错误 -

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

文件代码-

image: microsoft/dotnet:sdk

pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script: # Modify the commands below to build your repository.
          - export PROJECT_NAME=TestAWS/AWSLambda1/AWSLambda1.sln
          - dotnet restore
          - dotnet build $PROJECT_NAME
          - pipe: atlassian/aws-lambda-deploy:0.2.1
            variables:
              AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
              AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
              AWS_DEFAULT_REGION: 'us-east-1'
              FUNCTION_NAME: 'my-lambda-function'
              COMMAND: 'update'
              ZIP_FILE: 'code.zip'

项目结构是这样的-

问题出在这里:

PROJECT_NAME=TestAWS/AWSLambda1/AWSLambda1.sln

这是错误的路径。 Bitbucket Pipelines 将使用 Docker 图像中的特殊路径,例如 /opt/atlassian/pipelines/agent/build/YOUR_PROJECT ,来对您的项目进行 Git 克隆。

当您在 Pipelines Web 控制台中单击“Build Setup”步骤时,您可以看到:

Cloning into '/opt/atlassian/pipelines/agent/build'...

您可以使用 pre-defined 环境变量来检索此路径:$BITBUCKET_CLONE_DIR,如下所述:https://support.atlassian.com/bitbucket-cloud/docs/variables-in-pipelines/

在你的 yml 构建脚本中考虑这样的事情:

script:
  - echo $BITBUCKET_CLONE_DIR # Debug: Print the $BITBUCKET_CLONE_DIR
  - pwd # Debug: Print the current working directory
  - find "$(pwd -P)" -name AWSLambda1.sln # Debug: Show the full file path of AWSLambda1.sln

  - export PROJECT_NAME="$BITBUCKET_CLONE_DIR/AWSLambda1.sln"
  - echo $PROJECT_NAME
  - if [ -f "$PROJECT_NAME" ]; then echo "File exists" ; fi

  # Try this if the file path is not as expected
  - export PROJECT_NAME="$BITBUCKET_CLONE_DIR/AWSLambda1/AWSLambda1.sln"
  - echo $PROJECT_NAME
  - if [ -f "$PROJECT_NAME" ]; then echo "File exists" ; fi