Regex in environment variables

circle.yml

#1

I want to set a variable in a build job that will be used in a the hugo command to set the baseurl. The branch is “docdock-baseurl”, so I want the hugo command to end with “docdock”. So far I have tried:

  • ${CIRCLE_BRANCH}/-baseurl/
  • ${CIRCLE_BRANCH/-baseurl/}
  • (${CIRCLE_BRANCH} | sed “s/-baseurl//”)
  • ({CIRCLE_BRANCH} | sed “s/-baseurl//”)

You can probably tell I’m shooting in the dark, but I also don’t see anything on the docs or otherwise that talks about regex in variables.

Here’s my config:

build-prod:
    docker:
        - image: jmminy/alpine-hugo-git-bash:latest
    working_directory: ~/project
    environment:
        VERSION: ${CIRCLE_BRANCH}/-baseurl/
    steps:
        - checkout
        - run:
            name: Building site
            command: hugo -v --baseURL http://example.com/${VERSION}

Thanks!


#2

After more digging, I found: https://circleci.ideas.aha.io/ideas/CCI-I-67

It says there that environment parameters are literal. The workaround is to add an export in the same run action:
- run:
command: |
export PATH=/go/bin:$PATH

I’ll see about adding something to the docs.


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.