更改jenkins管道以使用github而不是gitlab [英] Change jenkins pipeline to use github instead of gitlab

查看:144
本文介绍了更改jenkins管道以使用github而不是gitlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jenkins管道中运行了一组自动化测试,测试代码位于gitlab中. 我从gitlab中提取代码的部分如下所示:

I have a set of automated tests that are ran in a jenkins pipeline, testcode is located in gitlab. The section where I pull code from gitlab looks like this:

我使用在那里已经存在的gitlab凭据(因为其他项目使用相同的gitlab凭据).

I use gitlab credentials that were already present there (since other project use the same gitlab credentials).

我使用位于测试代码库中的简单jenkinsfile从此处运行脚本.大致是这样:

I use a simple jenkinsfile that is located in the test codebase to run the script from here. This is roughly how it looks:

  agent {
    kubernetes {
      defaultContainer 'jnlp'
      yaml """
        apiVersion: v1
        kind: Pod
        metadata:
          labels:
            application: auto_ish
        spec:
            containers:
              - name: node
                image: node:12.14.1
                command:
                - cat
                tty: true
      """
    }
  }
  stages {
    stage('Build') {
      steps {
        container('node') {
            sh '''
                npm install
            '''
        }
      }
    }

    stage('Test') {
      steps {
        container('node') {
          sh 'node_modules/.bin/wdio ./test/config/wdio.conf.acc.js --suite SmokeTest --mochaOpts.grep=@smoke' 
         }
      }
    }

我的问题:

我的自动化测试的代码库最近已移至github,而让它无法在jenkins中工作也很困难.对于github,我有一个我需要使用的个人访问令牌,因此没有像gitlab那样的私钥.我曾尝试将此令牌添加到凭据管理器,但添加后不会显示在下拉列表中.

The codebase of my automated tests has recently been moved to github, and I have trouble getting it to work in jenkins. For github I have a personal access token that I need to use, so no private key like I had for gitlab. I have tried adding this token to the credentials manager, but after adding it doesnt show up in the dropdown.

我遵循了一些演练,告诉我为jenkins安装github插件,然后在jenkins配置中设置我的个人访问令牌,如下所示:

I followed some walkthroughs that told me to install github plugins for jenkins and then set my personal access token in jenkins configuration like this:

我测试了连接,并且连接正常.

I tested the connection,and it worked.

从现在开始,我不知道如何进行.我只想从代码库中提取代码以运行项目.将代码推送到github时无需触发构建,因为我的测试是在其他作业完成时触发的.

From here on, I have no idea how to proceed. I just want to pull the code from the codebase to run the project. No need to trigger builds when code is pushed to github, since my tests are triggered when other jobs finish.

但是由于我的凭据不在凭据管理器中,因此我不能仅在此处添加新的存储库.这也意味着我无法在此处引用我的jenkinsfile.

But since my credentials are not in the credentialsmanager, I cannot just add the new repo here. This also means I cannot refer to my jenkinsfile here.

我在某处阅读了我必须在这里引用我的github项目的内容: 我做到了,但我认为这还不够.我认为我需要从新存储库中提取代码,但是我不知道在哪里.

I read somewhere I had to refer to my github project here: I did this, butI think this will not be enough. I figure I need to pull the code from the new repo somewhere, but I have no idea where.

这带给我的问题是:使用我指定的个人acces令牌/github服务器,如何在哪里以及如何从github存储库中提取代码?

Which brings me to my question: where and how do I pull the code from my github repo, using the personal acces token/github server I specified?.

推荐答案

经过密集的搜索后,我找到了答案,事实证明,答案要容易得多,

After some intense googling I found the answer, which proved to be a lot easier then I thought:

显然,就詹金斯而言,至少可以像密码一样使用个人访问令牌.我向凭证管理器添加了新凭证,选择了用户名和密码"类型,输入了一个不存在的用户名("user"),并将个人访问令牌放在了密码字段中.

Apparently a personal access token can be used like a password, as far as jenkins is concerned atleast. I added new credentials to the credential manager, chose type 'username and password', put in a non existing username ('user') and put the personal access token in the password field.

这样,我可以像以前一样从下拉菜单中选择凭据,并且项目被克隆而没有任何问题

This way I could choose the credentials from the dropdown like I did before, and the project was cloned without issues

这篇关于更改jenkins管道以使用github而不是gitlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆