I'm using Jenkins to run tests before deploying to Heroku using a git publisher plugin. I want to sandwich my deploy with maintenance mode ON/OFF but don't want to install the heroku toolbelt (reference) on my jenkins machine (nor do I want to go to the Web UI and toggle the maintenance mode manually). I don't want to install the heroku toolbelt on jenkins because it adds to the customization and configuration I'd need to do to the jenkins installation and I want to keep my jenkins instance as disposable as possible...driven rather by source code pipelines (Jenkinsfile).
Ideas:
utilize a docker image that has the heroku toolbelt installed on it
utilize a multi-buildpack that does it for me?
Any suggestions or experience on how I might accomplish this?
You can use heroku's platform api to do this:
https://devcenter.heroku.com/articles/platform-api-reference#app-update
The following curl request will put your app into maintenance mode:
curl -n -X PATCH https://api.heroku.com/apps/$APP_ID_OR_NAME \
-d '{"maintenance": true}' \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3"
-H "Authorization: Bearer <heroku token>
You will just need to replace the app name, as well as the token.
You can generate OAuth tokens using the cli-oauth cli plugin locally.
Related
Need help for creating tag for every bit bucket commit.
Please let me know if anyone have implemented this using Jenkins pipeline, if yes how can we achieve that
I'm going to assume you have some sort of Multi-branch pipeline job set up, or some mechanism to trigger a jenkins job for each commit to BitBucket. Bitbucket will need to trigger a Jenkins job for each commit via a webhook
In your pipeline code, you'll need to do the following:
Get the hash of your commit. You can get this data from the GIT_COMMIT variable in the Git Jenkins Plugin
Create a Bitbucket tag via their api with the commit hash mentioned above
curl https://api.bitbucket.org/2.0/repositories/jdoe/myrepo/refs/tags \
-s -u jdoe -X POST -H "Content-Type: application/json" \
-d '{
"name" : "new-tag-name",
"target" : {
"hash" : "a1b2c3d4e5f6",
}
}'
There are few different ways to do #2.
Put that code in a powershell script and run it from your job.
Call it directly from your jenkins pipeline like this stackoverflow answer.
Or if you plan to do this from many jobs, you could also create your own Bitbucket Api Client shared library that does the api interaction for you.
Note: You'll likely need to authenticate these Bitbucket api requests
I was able to get rid of error using env.GIT_COMMIT
I'm developing a bash script to automatic clone some projects and another task in dev VM's, but we have one project in Heroku and repository is in it. In my .sh file I have:
> heroku login
And this prompt to enter credentials, I read the "help" guide included on binary and documentation but I can't found anything to automatic insert username and password, I want something like this:
> heroku login -u someUser -p mySecurePassword
Exist any way similar to it?
The Heroku CLI only uses your username and password to retrieve your API key, which it stores in your ~/.netrc file ($HOME\_netrc on Windows).
You can manually retrieve your API key and add it to your ~/.netrc file:
Log into the Heroku web interface
Navigate to your Account settings page
Scroll down to the API Key section and click the Reveal button
Copy your API key
Open your ~/.netrc file, or create it, with your favourite text editor
Add the following content:
machine api.heroku.com
login <your-email#address>
password <your-api-key>
machine git.heroku.com
login <your-email#address>
password <your-api-key>
Replace <your-email#address> with the email address registered with Heroku, and <your-api-key> with the API key you copied from Heroku.
This should manually accomplish what heroku login does automatically. However, I don't recommend this. Running heroku login does the same thing more easily and with fewer opportunities to make a mistake.
If you decide to copy ~/.netrc files between machines or accounts you should be aware of two major caveats:
This file is used by many other programs; be careful to only copy the configuration stanzas you want.
Your API key offers full programmatic access to your account. You should protect it as strongly as you protect your password.
Please be very careful if you intend to log into Heroku using any mechanism other than heroku login.
You can generate a non-expiring OAuth token then pass it to the CLI via an environment variable. This is useful if you need to run Heroku CLI commands indefinitely from a scheduler and you don't want the login to expire. Do it like this (these are not actual Tokens and IDs, BTW):
$ heroku authorizations:create
Creating OAuth Authorization... done
Client: <none>
ID: 80fad839-876b-4ea0-a41e-6a9a2fb0cf97
Description: Long-lived user authorization
Scope: global
Token: ddf4a0e5-9294-4c5f-8820-b51c52fce4f9
Updated at: Fri Aug 02 2019 21:26:09 GMT+0100 (British Summer Time) (less than a minute ago)
Get the token (not the ID) from that authorization and pass it to your CLI:
$ HEROKU_API_KEY='ddf4a0e5-9294-4c5f-8820-b51c52fce4f9' heroku run ls --app my-app
Running ls on ⬢ my-app... up, run.2962 (Hobby)
<some file names>
$
By the way this also solves the problem of how to use the Heroku CLI when you have MFA enabled on your Heroku account but your machine doesn't have a web browser e.g., if you are working on an EC2 box via SSH:
$ heroku run ls --app my-app
heroku: Press any key to open up the browser to login or q to exit:
› Error: quit
$ HEROKU_API_KEY='ddf4a0e5-9299-4c5f-8820-b51c52fce4f9' heroku run ls --app my-app
Running ls on ⬢ my-app... up, run.5029 (Hobby)
<some file names>
$
EDIT: For Windows Machines
After you run heroku authorizations:create, copy the "Token", and run the following commands:
set HEROKU_API_KEY=ddf4a0e5-9299-4c5f-8820-b51c52fce4f9
heroku run ls --app my-app
If your goal is just to get the source code, you could use a simple git client. You just need the api key.
Steps to get api key
Log into the Heroku web interface
Navigate to your Account settings page
Scroll down to the API Key section and click the Reveal button
Copy your API key
Download source code using git
Use this url template for git clone
https://my_user:my_password#git.heroku.com/name_of_your_app.git
In my case the user value was my email without domain.
Example :
if mail is **duke#gmail.com**
user for heroku auth will be **duke**
Finally just clone it like any other git repositories:
git clone https://duke:my_password#git.heroku.com/name_of_your_app.git
I agree that Heroku should have by now provided a way to do this with their higher level CLI tool.
You can avoid extreme solutions (and you should, just like Chris mentioned in his answer) by simply using curl and the Heroku API. Heroku allow you to use your API Token (obtainable through your user settings / profile page on the Heroku dashboard).
You can then use the API to achieve whatever it is you wanted to do with their command line tool.
For example, if I wanted to get all config vars for an app I would write a script that did something like the following:
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer YOUR_TOKEN```
If *YOUR_APP_NAME* had only one config variable called *my_var* the response of the above call would be
{
"my_var": some_value
}
I've found using this all the time in CI tools that need access to *Heroku* information / resources.
I have setup a Teamcity Project in Windows system within Teamcity.
But I wish to trigger the Teamcity build from Windows command prompt.
Is this possible?
If yes, Is there any documentation or setup guide for this?
Taken from the TeamCity documentation:
curl -v -u user:password http://teamcity.server.url:8111/app/rest/buildQueue --request POST --header "Content-Type:application/xml" --data-binary #build.xml
https://confluence.jetbrains.com/display/TCD9/REST+API#RESTAPI-TriggeringaBuild
Say my fat fingers managed to set my BLOWERIO_URL to something invalid:
$ heroku config:set BLOWERIO_URL=https://{user:pass}#api.blower.io/ --app recon-trac
How can I recover the correct, working BLOWERIO_URL?
I haven't been able to find any troubleshooting guides in Heroku's so-called "support" section, and Google isn't much help either.
I'm getting "400 Bad Request" when I try to send an SMS. It was broken earlier, and I fixed it by changing the BLOWERIO_URL, and now it's broken again.
Run this command to open a control panel for Blower.io:
heroku addons:open blowerio --app your-app-name
Clicking on the Send SMS tab will show you a command you can use to test. The command includes the URL:
curl -X POST -d "to=+14155550000&message=This is a test from Blower.io" -H "Accept: application/json" https://12345678-9abc-def0-1234-56789abcdef0:a1B2c3D4e5F6g7H8i9J0k1#api.blower.io/messages
You want to copy everything from https to the end, except messages.
https://12345678-9abc-def0-1234-56789abcdef0:a1B2c3D4e5F6g7H8i9J0k1#api.blower.io/
Now you can set your Heroku BLOWERIO_URL appropriately:
heroku config:set BLOWERIO_URL=https://12345678-9abc-def0-1234-56789abcdef0:a1B2c3D4e5F6g7H8i9J0k1#api.blower.io/ --app your-app-name
Thanks to Glenn Gillen from Blower.io Support for getting me straightened out.
I am currently setting up Parse Cloud Code and I have gotten to the final step which is to deploy the main.js file but when I do this it just opens the file in Adobe Dreamweaver?
I was having problems understanding how to deploy the main.js file.
Read the following steps: https://www.parse.com/apps/quickstart#cloud_code/unix
It contains:
Get the Parse tool
Download the command line tool by running this command:
curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
This installs a tool named parse to /usr/local/bin/parse. That is the only thing that's added, so to uninstall, just delete that file. Running this command will also update your existing Parse command line tool if you already have it installed.
Set up a Cloud Code directory
Open a new terminal window, run the command parse new and follow the instructions.
$ parse new
Please login to Parse using your email and password.
Email: ninja#gmail.com
Password (will be hidden):
Would you like to create a new app, or add Cloud Code to an existing app?
Type "new" or "existing": existing
1:MyApp
2:MyOtherApp
Select an App to add to config: 1
Awesome! Now it's time to setup some Cloud Code for the app: "MyApp",
Next we will create a directory to hold your Cloud Code.
Please enter the name to use for this directory, or hit ENTER to use
"MyApp" as the directory name.
Directory Name: MyCloudCode
Your Cloud Code has been created at ${CLOUD_CODE_DIR}.
Next, you might want to deploy this code with
"parse deploy"
.
This includes a "Hello world" cloud function, so once you deploy
you can test that it works, with:
curl -X POST \
-H "X-Parse-Application-Id: ${APP_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{}' \
https://api.parse.com/1/functions/hello
$ cd MyCloudCode
Go to the directory where your Main.js file does exist and
use command $parse deploy to deploy your code on parse cloud.Refer this link if you are using Linux system.https://www.parse.com/apps/quickstart#cloud_code/unix and use this link if you are using windows system https://parse.com/apps/quickstart#cloud_code/windows.
Hope it will help.
As far as I understand from your question, you want to deploy the main.js file to the Parse cloud. The problem that you face opening in Adobe Dreamweaver is related with your computer where you configure the file open with the Adobe Dreamweaver.
The answer to your question is; as detailed in Parse Cloud tutorial, first you have to install Parse command line tool. This tool enables you to manage your code in Parse cloud. Then you can use "parse new" command to set up a cloud directory where you have to replace the main.js file with your own. Following that "parse deploy" will deploy your js file to the Parse cloud. You can find detailed information in tutorials Parse Cloud. Hope this helps.
Regards.