1
votes

while doing build in github actions, I would like to set docker image name, based on branch name ie: base-name-develop

I tried for example:

image-name: my-service:$(ref=${GITHUB_REF%refs/heads/master};echo ${ref:=latest})

but it does not work, looks like is try to set name with all those $( etc. ;) instead of echo it

1

1 Answers

1
votes

ok finally found solution

first we need to set variable:

- name: Extract Branch Name
      shell: bash
      run: |
        branchName=${GITHUB_REF#refs/heads/}
        if [ $branchName = 'develop' ]; then additionalImageName='-develop'; else additionalImageName=''; fi
        echo "::set-output name=additionalImageName::$(echo $additionalImageName)"
      id: extract_branch

and then in creating docker container step:

- name: docker
      uses: VaultVulp/[email protected]
      with:
        image-name: test-service${{ steps.extract_branch.outputs.additionalImageName }}

looks like only way to use some variable in image-name is by using steps. Anyway it works well.