Do Upstart job configuration files have their own variables? - upstart

There is a lot of discussion about how environment variables work in upstart, and that they aren't available to the upstart job configuration. Do upstart job configurations have their own form of variable to do something like:
...
myworkingdir=/opt/specialpackage
chdir $myworkingdir
exec $myworkingdir/bin/executable1 run-program $myworkingdir/bin/executable2 param1 param2

Environment variables are not available in Job Configuration File. All job processes are children of init which does not have a user's environment. Init is parent of all processes.
However, environment variables could be set in Job Configuration File and it is possible to pass variables from a user environment to job.
It is possible to define variables in form myworkingdir=/opt/specialpackage but such variable will be available only in the section in which it is defined.
For details check Environment Variables.

Related

Why Rundeck can't read custom remote node environment variables

I tried to run some commands on a remote node to test if Rundeck can display its environment variables, and it's weired that Rundeck can read the default env vars but not mine :
And result is :
I have defined my custom environment variables in different places (inside /etc/profile and ~/.bash_profile) but no luck..
Non interactive bash shell reads from .bashrc not .bash_profile. You might move your env var setting to .bashrc and source that file from .bash_profile.

How to add secret variable as task environment variable in VSTS

This documentation states that secret variables are
Not decrypted into environment variables. So scripts and programs run by your build steps are not given access by default.
One of my build tasks require that an environment variable be set that is stored in a secret variable. Does this mean it's impossible to do this using secret varaibles in VSTS? If not, how do I do this?
For further background, I'm trying to code sign my electron app using electron-builder. It requires that two environment variables be set: CSC_LINK and CSC_KEY_PASSWORD. One of these is the password to a code signing certificate so needs to be kept secure.
Set Environment Variable
Use a Command Line task, like this:
target_environment_variable now contains the value of secret_variable.
Verify
Add a subsequent Command Line task that writes all environment variables to a disk file, like this: (note: in the Arguments text box, write to a folder that both you and build agent can access):
Queue the build definition, then view the file containing the environment variables:
When using the YAML-syntax this can be achieved too:
steps:
- script: |
echo %MYSECRET%
env:
MySecret: $(Secret_Variable)
You can supply variables to pass to tasks in the Variables page of the build definition:
Then they can be passed in to a task as an input like so:

Can Bamboo variables be overridden by a Script task?

I'm interested in using a script task to override one of these Bamboo plan variables for subsequent tasks but I'm not sure if it's possible or how to go about doing so. It appears that Bamboo allows for various levels of variable overrides for Build Plans all the way down to particular branches however they all seem to require defining the values within the Bamboo UI. The problem with this is that it requires admin privileges to modify these variables whereas some of them need to be modified by developers that do not have this level of access. As a solution I want to be able to specify some variable overrides in files that exist in the source repository itself.
Attempt 1: Overriding environment variables
I've attempted to set the environment variables exposed by Bamboo using a Powershell script and specifying something like $env:bamboo_xyz = 'ABC' but it doesn't seem to have an effect past the task context in which it was specified in. Presumably Bamboo must be re-setting the environment variables individually for each task or executing them within their own contexts but it's not clear to me exactly from the documentation.
UPDATE: It appears from some testing that environment variables set in one Script task are not available in subsequent Script tasks in the same Job. This leaves me with no apparent way to override variables based on anything other than hard coded values in Bamboo.
Attempt 2: Using the Bamboo Inject Variables Plugin task
I've tried using the Bamboo Inject Variables Plugin task to override variables but because what appears to be a required namespace parameter it only seems to be able to define new variables and not override existing ones.
Enviroment variables are only valid in the current session. So if bamboo starts one script ( one powershell session ) completes that and then start a new powershell script ( New Session ) the enviroment variable will not be kept.
So then there are a few options, set the variable in each script.
Or set it using registry at the start of the process. And if ncessary set it back to default value in the last step/script.

Rudeck: Using node environment variables, inside a scheduled job

I have a scheduled job on rundeck (2.6.2).
This jobs run a script that needs an node environment variable available (like $HOME, $USER or $PWD. A custom one. ) for all user in the node/nodes.
I could use jobs options to solve this if I wanted trigger the job from API ( Or manually. Rundeck ask me for the option ) but is a scheduled job. I can't use Options -> Default Value because the jobs could run in nodes with different values for this environment variable.
There is any way to offers all / some node environment variables to rundeck to be used inside the scheduled jobs?
(I have thought in use Options -> Allowed Values -> Remote URL but is a mess. Too complicated to me requirement)
Thanks.
The easy way in my case has been to customize /etc/rundeck/profile adding into it all the stuff I wanted.
Seems a pretty good solution to me.
I succeeded to perform this by adding the following lines:
set -a
. /etc/environment
. /etc/profile
1) put those lines into the file: /etc/rundeck/profile
2) put those lines into a script step
Remark: I'm using only script steps in my rundeck and I'm always put this lines in the first line of the script step:
#!/usr/bin/env bash

Reload environment variables inside powershell window

In my Powershell script I'm setting machine-level environment variables with:
[Environment]::SetEnvironmentVariable("MY_VARIABLE", "MY_VALUE", "Machine")
Inside this same script, I am calling another application that will look for the variable above. Is there a way for me to reload the current session with the variables I created above?
No but you can also set the environment variables for the current process i.e. $env:MY_VARIABLE = 'MY_VALUE'. Any application you start should inherit the environment variables set in this fashion.