Bitbucket自动部署到Linux服务器(DigitalOcean Droplet)

huangapple go评论39阅读模式
英文:

Bitbucket auto deploy to Linux server (DigitalOcean Droplet)

问题

遇到了一个问题,尝试使用BitBucket Pipeline将我的代码部署到运行Ubuntu的Droplet服务器时。

我已经设置了必要的环境变量(SSH_PRIVATE_KEY,SSH_USER,SSH_HOST),并将SSH_PRIVATE_KEY的公钥添加到服务器上的~/.ssh/authorized_keys文件中。当我手动从服务器部署时,克隆或拉取没有任何问题。然而,在自动CI部署阶段,我遇到了附图中显示的错误。

这是我的.yml配置。

谢谢您提前的帮助。

英文:

I have encountered a problem while attempting to deploy my code to a Droplet server (running Ubuntu) using BitBucket Pipeline.

I have set the necessary environment variables (SSH_PRIVATE_KEY, SSH_USER, SSH_HOST) and added the public key of the SSH_PRIVATE_KEY to the ~/.ssh/authorized_keys file on the server. When I manually deploy from the server, there are no issues with cloning or pulling. However, during the automatic CI deployment stage, I am encountering the error shown in the attached image.

Bitbucket自动部署到Linux服务器(DigitalOcean Droplet)

This is my .yml configuration.

Bitbucket自动部署到Linux服务器(DigitalOcean Droplet)

Thanks for helps in advance.

答案1

得分: 0

要引用配置中定义的变量的值,你的脚本应该使用$VARIABLE_NAME,而不是VARIABLE_NAME,因为后者只是字面字符串。

- pipe: atlassian/ssh-run:latest
  variables:
    SSH_KEY: $SSH_KEY
    SSH_USER: $SSH_USER
    SERVER: $SSH_HOST
    COMMAND: "/app/deploy_dev01.sh"

另外,注意当使用显式的$SSH_KEY 时存在一些潜在问题,通常更容易和更安全地使用Bitbucket提供的默认密钥,参见https://stackoverflow.com/q/75156014/11715259。

英文:

To refer to the values of the variables in defined in the configuration, you script should use $VARIABLE_NAME, not VARIABLE_NAME as that is literally that string.

- pipe: atlassian/ssh-run:latest
  variables:
    SSH_KEY: $SSH_KEY
    SSH_USER: $SSH_USER
    SERVER: $SSH_HOST
    COMMAND: "/app/deploy_dev01.sh"

Also, note some pitfalls exists when using an explicit $SSH_KEY, it is generally easier and safer to use the default key provided by Bitbucket, see https://stackoverflow.com/q/75156014/11715259

huangapple
  • 本文由 发表于 2023年2月9日 02:45:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390391.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定