I tried to use the file
image: node:8.11.1
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- npm install -g pm2
- pm2 deploy production
but it always throws with "Host key verification failed". I realize that pm2 require ssh keys to deploy. It there any work-arounds?
Hi @HaroldFrost
You can set up SSH keys and known hosts in pipelines. Please refer to this page of the documentation for details: https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html
Hello @StannousBaratheon, I had the same problem but to add an existing ssh key, Bitbucket asking for both public and private key? I only have the private key by default and don't have a public key. So how could I overcome this?
Answers are appreciated. Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Pipelines allows you to enter the public key so that you can store both private and public keys together. It only uses the private key during the build process however so if you don't have the public key you may set any value and SSH will still work as desired.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, @StannousBaratheon for your response. I have one more doubt. Below goes my PM2 ecosystem config file.
module.exports = {
apps: [
{
name: "my-app",
script: "./app.js"
}
],
deploy: {
production: {
user: "ubuntu",
host: "ec2-xx-xxx-xxx-xx.us-east-2.compute.amazonaws.com",
key: "~/.ssh/AWS-EC2-INSTANCE-LIVE.pem",
ref: "origin/master",
repo: "git@bitbucket.org:User/my-app.git",
path: "/home/ubuntu/my-app",
"post-deploy":
"npm install && pm2 startOrRestart ecosystem.config.js"
}
}
};
And here goes my PM2 deploy command in a package.json file,
"deploy" : "pm2 deploy ecosystem.config.js production"
And below goes my bitbucket pipeline script block
script: # Modify the commands below to build your repository.
- npm install
- npm run-script deploy
Now I have added the AWS-EC2-INSTANCE-LIVE.pem (Private key) in my Bitbucket project repo and given some public key as some value.
Now, how to refer this private key (ssh key added in repo settings) in my PM2 ecosystem config file? How PM2 know there is a private key in BitBucket and how it refers to it?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Pipelines makes your key available at: `/opt/atlassian/pipelines/agent/data/id_rsa` during the build.
It also configures it as a default identify file in ~/.ssh/config so that build tools that respect ssh configuration work automatically.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, @StannousBaratheon. Still, I am facing syntax problem I guess. The following is my updated PM2 ecosystem config script in a key path.
key: "/opt/atlassian/pipelines/agent/data/id_rsa"
But still, it says, Host key verification failed. What am I missing?
Any idea?
Note: I added a key in my Project repository. Not in my account.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@StannousBaratheon in my case, a pipeline is trying to read a key from '/root/.ssh/id_rsa' location and gives me error like "No such file or directory.
Permission denied (publickey).
" my key is under ec2user and not in root user..how to specify the path in the pipeline?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Pipelines doesn't read the key per se but rather the build tool you're using within pipelines likely looks in the current user directory for a configured key. Since most Docker images start as the root user by default, the user's home directory will be /root
If you're creating this Docker image you can change the default user by adding the USER directive to your dockerfile (see https://docs.docker.com/engine/reference/builder/#user).
Otherwise, can you please provide additional information about what you're trying to do including the Docker image, build tooling etc. so that we can assist further?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.