Jenkins - Git Submodule Credentials与Parent Repo不同

时间:2017-11-13 23:41:58

标签: git github jenkins jenkins-plugins jenkins-job-builder

背景

Jenkins正被用于从具有Git子模块的Git仓库构建工件。子模块与父项目不在同一个repo中,甚至不在同一端点。问题是父repo检查正常,因为凭证ssh密钥A与主/父repo相关联,但不出意外,在子模块上失败,因为凭证ssh密钥B与Jenkins&的repo没有关联#39;观点。

令人惊讶的是Jenkins对Git子模块没有更好的开箱即用支持;贡献的时间。

问题

  1. 有没有办法为单个Git仓库存储多个凭据?
  2. 如果答案是否定的,为什么Jenkins在高级子模块行为下提供使用来自父存储库的默认远程数据库的凭据的选项,如下所示?< / LI>
  3. 还有哪些方法可以处理具有不同凭据的Jenkins和Git子模块?
  4. enter image description here

    系统信息

    在Docker Machine上运行Jenkins(本地)

    在CentOS上运行Jenkins(生产)

    Jenkins版本:2.60.2(两者)

    Git插件版本:3.6.4(两者)

1 个答案:

答案 0 :(得分:1)

是的,这很容易做到。您可以创建pub / private密钥对,并将其设置为github deploy key(如果不使用git hub,则将其设置为使用的密钥集)。您可以将其添加为Jenkins凭据(前提是已安装凭据插件)。

public function index(Request $request) {

    if($request->isMethod('post')){
    $search_first_name =    $request->search_first_name;
    $search_last_name =     $request->search_last_name;
    $search_email =         $request->search_email;
    $search_round_number =  $request->search_round_number;
    $search_location =      $request->search_location;

    $options = Input::get('dropdown');

    if($options == 'recommendation' || 'source')   {
            $recOrSource = Input::get('options');
            unset($options);  
    }

    $search_from_date =      $request->search_from_date;
    $search_to_date =      $request->search_to_date;

    $candidate = DB::table('candidates')
                ->when($search_first_name, function ($query) use ($search_first_name) {
                    return $query->where('first_name', 'like', '%' . $search_first_name . '%');
                })
                ->when($search_last_name, function ($query) use ($search_last_name) {
                    return $query->where('last_name', 'like', '%' . $search_last_name . '%');
                })
                ->when($search_email, function ($query) use ($search_email) {
                    return $query->where('email', $search_email);
                })
                ->when($search_round_number, function ($query) use ($search_round_number) {
                    return $query->where('round_number', $search_round_number);
                })
                ->when($search_location, function ($query) use ($search_location) {
                   return $query->where('location', $search_location);
                })                       
                ->when($options, function ($query) use ($options,$search_from_date,$search_to_date  ) {
                   return $query->whereBetween($options, array($search_from_date, $search_to_date));
                })    
                ->when($recOrSource, function ($query) use ($recOrSource,$search_from_date,$search_to_date  ) {
                   return $query->where(!empty($recOrSource))->whereBetween('created_at', array($search_from_date, $search_to_date));
                })                                                                                     
                ->orderBy('first_name', 'asc')
                ->orderBy('last_name', 'asc')
                ->get();                     

                Session::flash('inputs', [
                    'search_first_name' => $search_first_name,
                    'search_last_name' => $search_last_name,
                    'search_email' => $search_email,
                    'search_round_number' => $search_round_number,
                    'search_from_date' => $search_from_date,
                    'search_to_date' => $search_to_date,
                    'search_location' => $search_location

                    ]);
            }else{
                 Session::forget('inputs');


    $candidate = Candidate::orderBy('first_name', 'asc')
                    ->orderBy('last_name', 'asc')
                    ->get();
                }

    return view('/candidates/index', [
        'candidate' => $candidate
    ]);

该ID映射到下面的 credentialsId

Username: git@github.com
Private Key:  the private key for that key set
Passphrase:  whatever passphrase you used
ID: aws-jenkins-github-deploykey (just an example name)
Description: some useful text

运行此流水线代码时,它将在分支中检出存储库,提交等到工作目录。您还可以指定目录。

因此,您可以使用它来签出一堆仓库并为其使用特定分支。