Scorpy47
Scorpy47

Reputation: 87

Bitbucket pipelines how to merge two variables to produce another variable to be used somewhere else

I am trying to workout a Bitbucket pipeline using the bitbucket-pipelines.yml

    image: microsoft/dotnet:sdk

pipelines:
 branches:
  master:
    - step:
        script:
          - dotnet build $PROJECT_NAME
          - export EnvrBuild=Production_$BITBUCKET_BUILD_NUMBER
          - '[ ! -e "$BITBUCKET_CLONE_DIR/$EnvrBuild" ] && mkdir $BITBUCKET_CLONE_DIR/$EnvrBuild'
          - dotnet publish $PROJECT_NAME --configuration Release
          - cp -r $BITBUCKET_CLONE_DIR/$PROJECT_NAME/bin/Release/netcoreapp2.1/publish/** $BITBUCKET_CLONE_DIR/$EnvrBuild
        artifacts:
          - $EnvrBuild/**

I am new to pipelines in Bitbucket. When I do an echo of $EnvrBuild I get the result right, but the $EnvrBuild does not have anything in the subsequent steps and it does not produce any artifacts, how ever if I hard code the values, it works. Is there a way to do something like $BITBUCKET_BUILD_NUMBER+"_"+$BITBUCKET_BRANCH ? (I know this is wrong, but you get the idea of what I am trying to achieve. Thank you in advance

Upvotes: 1

Views: 3030

Answers (1)

Alexander Zhukov
Alexander Zhukov

Reputation: 4557

Variable expansion is not allowed to specify artifacts, you have to provide a static value. However, you can store multiple subdirectories under your build directory using wildcards implicitly. Here is an example:

image: microsoft/dotnet:sdk

pipelines:
    branches:
      master:
        - step:
          script:
            - dotnet build $PROJECT_NAME
            - export EnvrBuild=Production_$BITBUCKET_BUILD_NUMBER
            - '[ ! -e "$BITBUCKET_CLONE_DIR/$EnvrBuild" ] && mkdir $BITBUCKET_CLONE_DIR/$EnvrBuild'
            - dotnet publish $PROJECT_NAME --configuration Release
            - mkdir -p $BITBUCKET_CLONE_DIR/build_dir/$EnvrBuild
            - cp -r $BITBUCKET_CLONE_DIR/$PROJECT_NAME/bin/Release/netcoreapp2.1/publish/** $BITBUCKET_CLONE_DIR/build_dir/$EnvrBuild
          artifacts:
            - build_dir/**
        - step:
          script:
            - export EnvrBuild=Production_$BITBUCKET_BUILD_NUMBER
            - ls build_dir/$EnvrBuild

Upvotes: 1

Related Questions