Search code examples
dockerbitbucketbitbucket-pipelines

How to pass multiple build-args variable to dockerfile


I am using a bitbucket-pipelines for my dotnet project. My project consist Dockerfile in the root directory and I want to pass multiple variable to that dockerfile but I am getting an error:

"docker build" requires exactly 1 argument.

Here is my step below:

- step:
        name: Build Image
        services:
          - docker
        script:
        - docker build \
          --build-arg VARIABLE_ONE=1 \
          --build-arg VARIABLE_TWO=2 \
          --build-arg VARIABLE_THREE=3 \
          --build-argVARIABLE_FOUR=4 \
          -t "$IMAGE_NAME" .

I tried the command locally on my bash terminal and its working but not working on pipeline


Solution

  • Remove the slashes.

        - docker build
          --build-arg VARIABLE_ONE=1
          --build-arg VARIABLE_TWO=2
          --build-arg VARIABLE_THREE=3
          --build-argVARIABLE_FOUR=4
          -t "$IMAGE_NAME" .
    

    Research YAML format and its string escaping rules > |. Check YAML to JSON converters to see what is the resulting string.