Travis CI encrypted secret environment variables - travis-ci

Having a problem with Travis on Github. I encrypted two environment variables using:
travis encrypt MY_SECRET_ENV=super_secret --add env.matrix
I see two encrypted values under env:matrix:-secure:
env:
matrix:
- secure:
kQeMLwvGVBl...
- secure:
h7SXfIif5Y...
If I look at the commit info, I can see the first ENV variable on the first commit, and the second ENV variable on the next commit. The tests indicate the the second ENV variable clobbered the first, and so I only have one ENV variable set: only one of two test passes, depending on which ENV variable "wins".
Is there a way to set two encrypted ENV vars in .travis.yml?

Answer is here.
The Travis CI docs use env:matrix in their example, but that sets up TWO test runs, one for each ENV variable.
Instead of env:matrix, use env:global, which will cause one test to run with multiple ENV variables.

Related

Accessing Jenkins-set environment variables from a Jenkins Plugin

If there is a Jenkins shell script build step, environment variables are set so that, for example, if you echo $WORKSPACE you see the current working directory. I am writing a custom plugin which also can execute shell commands but WORKSPACE is not set when this plugin executes.
I could see that Jenkins sets all those env variables prior to executing the shell commands the Jenkins project specifies so that they would not be already set for a custom plugin. If that is the case, it would seem like there is no way to access those env variables.
But if there is a way to obtain the values of the env variables that would be useful.

BRANCH env variable is undefined using gatsby cloud

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.

How to pass along custom variable created in .gitlab-ci.yml to Docker?

Within .gitlab-ci.yml I've created a new variable under script: by using $CI_COMMIT_SHA and modifying it. When I echo the variable it returns the proper value. However, I'm not having any success passing it along to Docker. What am I not doing right?
Ultimately, I would like access this custom variable inside my container.
build:
script:
# converts commit SHA to UNIX time
- export COMMIT_TIME_UNIX=$(git show -s --format=%ct $CI_COMMIT_SHA)
- echo $COMMIT_TIME_UNIX
You would need to check, when the same script is executed in a Docker/container environment, if it is still in the right Git repository path.
You can add, before the first export:
pwd
git status
env|grep GIT
That way, you will check if you are doing Git commands where you should, and if there is any GIT_xxx environnement variable which might influence said command.

VSTS secrets as environment variables

In the VSTS build, I set various variables (Edit build -> Variables tab), some I set as secret (click the lock), some I don't.
In the build, I run a command prompt task to run set -- e.g. show me all the environment variables. Those marked as secret aren't present.
How do I get VSTS secrets into environment variables?
Secret variables are:
Encrypted at rest with a 2048-bit RSA key.
Not returned back to the client. They are automatically masked out of
any log output from the build or release.
Not decrypted into environment variables. So scripts and programs run
by your build steps are not given access by default.
Decrypted for access by your build steps. So you can use them in
password arguments and also pass them explicitly into a script or a
program from your build step (for example as $(password)).
So, Secure variables need to be passed in to tasks as inputs. Check this case: How to add secret variable as task environment variable in VSTS

Jenkins build pipeline providing env vars for different environments

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?

Resources