【问题标题】:How to configure Jenkins for 2FA enabled github account?如何为启用 2FA 的 github 帐户配置 Jenkins?
【发布时间】:2021-12-13 20:54:01
【问题描述】:

我的帐户启用了 2FA,并且我的仓库是私有的。我正在尝试使用 Jenkins 将我的 node.js 应用程序部署到 AWS Ec2 并且一切正常,包括(构建、测试、覆盖),但由于 2FA 问题,最终部署不起作用。我已经在 jenkins 中添加了我的用户名和令牌,这似乎可以工作,但是一旦我运行像 git pull 这样的 git 命令,它会在运行时询问用户名和密码,因为 Jenkins 无法连接到 github 并且无法进行任何更改. 这是部署阶段:

stage('deploy') {
              steps {
                  withCredentials([usernamePassword(credentialsId: 'someid', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
                    echo 'Deploying to aws ec2'
                    sh '''#!/bin/bash
                    ssh ubuntu@ip-555.55.55.5 <<EOF
                     cd /var/www/app
                     sudo git reset --hard HEAD # problem is likely to be here because it requires username and password
                     sudo git pull
                     npm install
                     pm2 restart all
                     exit
                    EOF
                    '''
                  }

          }

【问题讨论】:

标签: node.js github jenkins jenkins-pipeline devops


【解决方案1】:

通过添加 ssh 密钥并将远程 url 更改为 Github ssh url 解决了这个问题。

【讨论】:

    猜你喜欢
    • 2017-09-30
    • 2021-08-20
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 2016-12-31
    • 2022-11-30
    • 2011-03-14
    相关资源
    最近更新 更多