Read-only variables
These variables are pre-defined for both Builds and Preview environments. They are set automatically and cannot be changed. You can reference them in your gatsby-config.js or anywhere else you would normally reference an environment variable.
BRANCH: The name of the current git branch. Useful for swapping environment variables depending on the branch.
CI: Always true.
GATSBY_CLOUD: Always true. Useful for checking if your build is running on Gatsby Cloud.
This is what gatsby cloud doc said.
but when I print out console for the process.env.BRANCH, it was undefined while process.env.GATSBY_CLOUD is true as expected.
Any help is welcomed.
Related
I have a Gatsby project that is integrated with a jenkins CI/CD pipeline. I define a variable in the jenkins pipeline like so:
environment {
my_env = "${env.GIT_BRANCH"
}
I have pipelines that run from the dev and master branches of the repo hosting my Gatsby project. I want to use this variable in my Gatsby config file so that when I run a pipeline gatsby will pull content from either the dev or master environments of the CMS I'm using.
The problem is Gatsby seems only able to read environment variables from .env files out of the box. I am not sure how to get it to read variable from something that's not a .env but also stored in the root (in this case, a jenkinsfile). Is there any workaround for this?
If you set your enviornment variable in jenkinsfile,and using the same agent , then you can just access that variable using env..
environment {
MY_ENV_VAR="myvalue"
}
// you can access using:
env.MY_ENV_VAR
In a config.json file that's passed to Auth0's deploy cli, I have the following variable defined in a config.json file:
"CALLBACKS": ["http://localhost:3000", "https://myapplication.com" ]
That variable can be overridden by an environment variable if it's present. I'm therefore trying to put the same value in the Deployment environment variables but it's not seeing it as an array.
Anything I should do to make it understand that the value above is not a string?
I have a public git repository that has a Jenkinsfile. The Jenkinsfile needs to be able to build three environments: dev, staging and production.
There's a set of variables that need to be set for each environment - some of these are sensitive and I wouldn't want to put them in the public repo. Some examples:
S3_BUCKET_URL
API_ENDPOINT
API_USERNAME
API_PASSWORD
etc.
In an ideal world I'd like a build parameter, e.g. BUILD_ENV that has the options: 'dev', 'staging' and 'prod' and some logic that sets the relevant vars dependent on env selection.
I've looked at the credentials pluglins, but they don't handle multiple envs and the UI seems awkward. Plus the env vars are accessible centrally, whereas we need them to be directly tied to the build job.
I've also looked at the env inject plugin, which works for setting properties, but there doesn't appear to be a way to make it vary those properties based on a chosen build parameter.
Is there a way to achieve this with the build pipeline? Surely there must be a plugin that already provides this capability?
I am new to Jenkins. I have it installed on a Windows server, running as a service. I have builds running fine, however, I am not able at all to get the environment variables to work. I have tried $BRANCH_NAME, ${BRANCH_NAME}, %BRANCH_NAME% and none of them work. I have setup a parameterized build where I set up a variable BRCHNAME with the default value of one of my branch names, but the variable does not get interpreted properly, it comes through as %BRCHNAME% when it executes the command.
This is from the console output:
C:\Program Files\Git\bin\git.exe rev-parse "origin/%BRCHNAME%^{commit}" # timeout=10
Say I've got dev, qa, and stable server environments for some web app, with corresponding git branches. Each environment should be continuously integrated. Each of these environments has a separate username/password pair used to publish the app. I would like to make a Jenkins multiconfiguration (matrix) job to publish to all of these environments. The publishing almost certainly must be done with a shell script.
My failed attempt consisted of using the Jenkins Credentials and Credentials Binding plugins. Credentials Binding provides a way to inject credentials as environment variables using a parameter. However, setting this parameter dynamically (i.e., something like if ENV == dev: CREDS = CREDS_dev) doesn't appear to be possible. Build scripts happen afterwards, and even using the Environment Script plugin doesn't work.
Is there any way for this to happen?
Had similar situation and used groovy script with parameterized build (https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin). In my case I had a choice parameter defined as "DEPLOY" and had different values, like "Test", "Release", then in the following groovy script (Evaluated Groovy script):
if ("Test".equals(DEPLOY)) {def map = [DEPLOY_URL: "http://someurl", DEPLOY_STORAGE: "testaccount"]; return map }
You should be able to specify your credentials in here or copy env variables. After that you can access these variables in windows batch command using:
echo %DEPLOY_URL%
echo %DEPLOY_STORAGE%
I also had another choice parameter defined "Deploy.Branch", with values of "dev" and "master". And used it as a parameter to Branches to Build, the value was set to (if you want to dynamically specify branch based on parameters):
*/${Deploy.Branch}
Hope this helps.
Here's what I ended up doing. It's kind of a workaround for what I would argue is a flawed design or missing use case in Jenkins.
Redid my creds so they have standard IDs (this is in the Advanced part and you can't set it after creation)
Matrix job runs a trivial script to figure out what env maps to what creds ID, then triggers...
The main job that does the deployment