I would like to assign custom variables using bash commands
image: alpine
pipelines:
  default:
      - step:
          name: docker-login
          services:
            - docker
          script:
            - docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
            - echo "logged in to docker hub"
            - echo $VERSION
          variables:
            VERSION: cat ./version.txt
      - step: 
          name: build-image
          services:
            - docker
          script:
            - echo "running docker image test"
      - step:
          name: 'set ssh env'
          script:
            - pipe: atlassian/ssh-run:0.4.0
              variables:
                SSH_USER: $SSH_USER
                SERVER: '$HOST'
                COMMAND: 'pwd'I am not getting the output of the file.. what is the correct syntax?
If your base image that step is running on doesn't support to set environment variables externally. you can not create variables like that. For example, your pipe image atlassian/ssh-run:0.4.0 has these environment variables set, so you can define. But docker-login step will be using image: alpine for its base and this base image doesn't have this environment variables set to be configured. There are three types of variables in Bitbucket (workspace variables, repository variables and deployment variables.) none of them meets your need in this use case. Because all these variable types are static and working as key/value.
We can try something else like below ;
image: alpine
pipelines:
  default:
      - step:
          name: docker-login
          services:
            - docker
          script:
            - docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
            - echo "logged in to docker hub"
            - export VERSION=$(cat ./version.txt)
            - echo $VERSION
Creating variables with linux commands will be helpful here. Also, pls keep in mind that these type of variables (in this case $VERSION variable) will only be identified in its step. If you want to carry it to other steps, you should use artifacts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With