Support Forums

Build - sed Update

My repository is using nrwl and has two website apps. The end goal is to have the ability to set netlify-plugin-cypress plugin’s configFile based on the netlify site that is building/deploying the code. Since both sites use the same netlify.toml, my hope was to use the sed command to set the variable in the file. Here’s what my setup looks like:

command = "sed -i -e \"s~__CYPRESS_CONFIG_PATH__~$CYPRESS_CONFIG_PATH~g\" netlify.toml && sed -i -e \"s~__PROJECT_NAME__~$PROJECT_NAME~g\" netlify.toml && nx build __PROJECT_NAME__ --prod"

# cache Cypress binary in local "node_modules" folder
# so Netlify caches it
CYPRESS_CACHE_FOLDER = "./node_modules/CypressBinary"
# set TERM variable for terminal output
TERM = "xterm"

# runs Cypress tests against the deployed URL. See: https://github.com/cypress-io/netlify-plugin-cypress#readme
package = "netlify-plugin-cypress"
record = true
configFile = "__CYPRESS_CONFIG_PATH__"
enable = true

Attempting to run it locally with this command:

PROJECT_NAME=site1-ui CYPRESS_CONFIG_PATH=cypress-site1-ui.json && echo "$PROJECT_NAME|$CYPRESS_CONFIG_PATH" && netlify build

I get this error:

$ sed -i -e "s~__CYPRESS_CONFIG_PATH__~$CYPRESS_CONFIG_PATH~g netlify.toml" && sed -i -e "s~__PROJECT_NAME__~$PROJECT_NAME~g netlify.toml" && __PROJECT_NAME__ --prod
sed: -e expression #1, char 50: unknown option to `s'

I’ve tried the following various commands (escaping/notescaping the sed command) using this page as reference:

sed -i -e s~__CYPRESS_CONFIG_PATH__~$CYPRESS_CONFIG_PATH~g netlify.toml && sed -i s~__PROJECT_NAME__~$PROJECT_NAME~g netlify.toml && nx build __PROJECT_NAME__ --prod

If I run the send command from the command line, it works as expected (replacing the variables)

Any idea what I’m doing wrong? Is there a better way to do this?

Do you mean you’re trying to update netlify.toml during the build?

If yes, that won’t work. I think you can use environment variables to point to the correct file.