I am trying to bulk set the environment variables for a Heroku pipeline since Heroku does not use the parent's environment variables in the pipeline anymore in the new version.
https://devcenter.heroku.com/articles/review-apps-new#configuration
I tried these but they don't work. I couldn't find any documentation for this. Any help would be much appreciated. Thanks.
heroku config:set KEY1=VALUE1 KEY2=VALUE2 --app my-pipeline
heroku config:set KEY1=VALUE1 KEY2=VALUE2 --pipeline=my-pipeline
You can copy all env var from another app as described here:
CONFIG_VARS=$(echo $(heroku config -a APPLICATION_NAME --json)) && curl -n -X PATCH https://api.heroku.com/pipelines/PIPELINE_ID}/stage/review/config-vars -d "$CONFIG_VARS" -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3"
Switch out APPLICATION_NAME with your app name and PIPELINE_ID witht the id of the pipeline you want to copy config vars to.
Related
Set up:
Using Github actions
One of the steps is using an aws send command to run some scripts on an ec2 instance (aws
cli reference here)
The script is just to copy a file from S3 onto the instance
I have an github environment variable which just have a path set as the
value
So code looks like this:
#setting github env variable
env:
PATH: C:\
#Script I'm using in my aws cli command
run: |
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--parameters 'commands=["Copy-S3Object -BucketName BUCKETNAME -Key FILENAME -LocalFolder \"${{ env.PATH }}\" -Force""]' \
This errors with
Error Response: "Copy-S3Object : The given path's format is not supported.
I can see it is running the commands as:
'"Copy-S3Object -BucketName BUCKETNAME -Key FILENAME -LocalFolder \'C:\\' -Force"'
So it is reading the slashes that i included to escape the quotation mark. So it think the filepath is literally \'C:\\'
Note: the quotations are needed round the github variable as it couldn't be read when i tried without
Questions
Can i not use a github environment within a script?
Any ideas on how to still escape the quotations but not have them show up in the script?
I have a question. Is it possible to assign output from az aritfacts universal download to variable?
I have a Jenkins job where I have script in shell like this:
az artifacts universal download \
--organization "sampleorganization" \
--project "sampleproject" \
--scope project \
--feed "sample-artifacts" \
--name $PACKAGE \
--version $VERSION \
--debug \
--path .
Then I would like transport the file to artifactory with this:
curl -v -u $ARTIFACTORY_USER:$ARTIFACTORY_PASS -X PUT https://artifactory.com/my/test/repo/my_test_file_{VERSION}
I ran the job but noticed that I passed to artifactory empty file. It created my_test_file_{VERSION} but it had 0 mb. As far as I understand I just created empty file with curl. So I would like to pass the output from az download to artifactory repo. Is it possible? How can I do this?
I understand that I need to assign file output to variable and pass it to the curl like:
$MyVariableToPass = az artifacts universal download output
And then pass this var to curl.
Is it possible? How can I pass files between Jenkins which triggers shell job to artifactory?
Also I am not using any plugin right now.
Please help.
The possible solution is to use a VM as the agent of the Jenkins, and then install the Azure CLI inside the VM. You can run the task in that node. To set a variable with the value of the CLI command, for example, the output looks like this:
{
"name": "test_name",
....
}
Then you can set the variable like this:
name=$(az ...... --query name -o tsv)
This is in the Linux system. If it's in the Windows, you can set it like this:
$name = $(az ...... --query name -o tsv)
And as I know, the command to download the file won't output the content of the file. So if you want to set the content of the file as a variable, it's not suitable.
I'm developing a Node application using Docker and docker-compose, which all have awesome ways to import multiple environment variables from a .env file.
Just wondering if there's a shortcut for updating a Heroku deployment's env vars instead of typing them out.
I've noticed there's no --env-file option on the official docs: https://devcenter.heroku.com/articles/config-vars
Using some xargs magic
cat .env.prod | xargs heroku config:set
# Output:
# API_PORT: 3000
# API_KEY_1: ab-cd
# DB_PORT: 6379
# REDISCLOUD_URL: xxx
Happily sets multiple args from a local .env file
I'd like to print all environment variables set on my Heroku server. How can I do that with command line only?
Ok, I found the way:
heroku config
The heroku run command runs a one-off process inside a Heroku dyno. The unix command that prints environment variables is printenv (manual page). Thus
heroku run -a app-name printenv
is the command you are looking for.
step 1 : list your apps
heroku apps
Copy the name of your app
step 2 : view config variables of this app
heroku config -a acme-web
Append --json to get the output as JSON.
heroku config -a acme-web --json
Append -s to get the output in shell format, to paste directly to a .env file, for example.
heroku config -a your-app -s
Is it possible to get a unique key per slug / release from a running dyno? I was following this article to setup RAILS_CACHE_ID (for expiring etags after deployments) but found that the dynos no longer ship with GIT configured (which causes this error):
fatal: Not a git repository (or any parent up to mount point /app)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
I also considered setting it in a config/initializers to the current Time but obviously that wouldn't work across multiple dynos. Any ideas?
There's a new (Nov 2015) labs feature which does just what you need "Dyno metadata" https://devcenter.heroku.com/changelog-items/768
heroku labs:enable runtime-dyno-metadata -a <app name>
Then on heroku:
~ $ env
HEROKU_APP_ID: 9daa2797-e49b-4624-932f-ec3f9688e3da
HEROKU_APP_NAME: example-app
HEROKU_DYNO_ID: 1vac4117-c29f-4312-521e-ba4d8638c1ac
HEROKU_RELEASE_VERSION: v42
HEROKU_SLUG_COMMIT: 2c3a0b24069af49b3de35b8e8c26765c1dba9ff0
HEROKU_SLUG_DESCRIPTION: Deploy 2c3a0b2
One solution is to use a git pre-push hook to set a heroku config value. Since it's done before the push and slug compilation, the config variable will be available as an ENV var to your rails app.
.git/hooks/pre-push:
#!/bin/sh
remote="$1"
url="$2"
while read local_ref local_sha remote_ref remote_sha
do
if [[ $url =~ heroku ]] ; then
app=$(git remote show -n $remote | sed -n -E -e 's/[[:space:]]+(Push[[:space:]]+URL)(\/|:).+(:|\/)(.*)\.git$/\4/gp')
echo Setting RAILS_CACHE_ID to $local_sha on app $app
heroku config:set RAILS_CACHE_ID=$local_sha --app $app
fi
done
exit 0
The pre-push.sample file has some documentation about the parameters that the hook is called with. I'm using verbose output of git remote to determine which app to set the config value on. The '-E' option for sed is for Mac OS X -- if you are using GNU sed replace that with '-r'.
Another solution is to use the heroku-api via a profile.d script to get the unique release id. This example uses curl to get the latest release id using the RANGE header. It's not the commit reference but it will be unique to every release, including rollbacks and config changes. You'll want to set the API_KEY and the APP_NAME as heroku config variables.
.profile.d/release.sh
# get release id and set as RAILS_CACHE_ID
# Heroku config variables that need to be set
# API_KEY: heroku api key (get from dashboard or `heroku auth:token`
# APP_NAME: set this to your app_name (this could be hardcoded in the profile.d script but
# would make it harder to manage apps with multiple environments
res=$(curl -s -H "Accept: application/vnd.heroku+json; version=3"\
-H "Authorization: Bearer $API_KEY"\
-H "Range: version ..; order=desc, max=1"\
-X GET https://api.heroku.com/apps/$APP_NAME/releases)
release_id=$(ruby -rjson -e "j = JSON.parse('$res'); puts j[0]['id']")
export RAILS_CACHE_ID=$release_id
In the rails app, ENV['RAILS_CACHE_ID'] should now be set to the most recent release id. You could also use this same strategy in a rails initializer.