reference

 

Gerrit Trigger

This plugin integrates with <a href="http://code.google.com/p/gerrit/" target="_blank" rel="nofollow noopener noreferrer">Gerrit</a> code review.

plugins.jenkins.io

 

Gerrit Trigger Plugin을 이용하여, Review commit이 올라올때 마다 Jenkins를 이용하여 빌드를 하였다.

이 때, 변경사항을 다음과 같은 방식으로 적용하였다.

cd vendor/google/tv/broadcaststack
git fetch "ssh://gerrit@gerrit.mycompany.net:29418/broadcaststack" ${GERRIT_REFSPEC} && git checkout FETCH_HEAD

 

그런데, 하나의 저장소에 대해서는 잘 동작하였으나, 여러 개의 저장소의 변경사항에 대해서는 위와 같은 방식이 적절하지 않았다. 즉, 변경사항을 추적할 저장소는 broadcaststack, projects/apple 이었는데, Jenkins script에서는 어느 저장소의 Patchset을 적용할지 ( 어느 디렉토리안에서 get fetch를 사용할지 ) 확인할 수 가 없었다.

 

Gerrit Trigger 플러그인 홈페이지에는 다음과 같은 예제가 있었다. 

repo init -u git://gerrit.mycompany.net/mymanifest.git
repo sync
repo download $GERRIT_PROJECT $GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER

그런데, repo download 명령어는 이전에 사용한 경험이 없어서, help를 찾아보았다.

$ repo help download

Summary

Download and checkout a change

Usage: repo download {[project] change[/patchset]}...

Options:
  -h, --help         show this help message and exit
  -c, --cherry-pick  cherry-pick instead of checkout
  -r, --revert       revert instead of checkout
  -f, --ff-only      force fast-forward merge

Description

The 'repo download' command downloads a change from the review system
and makes it available in your project's local working directory. If no
project is specified try to use current directory as a project.

약간의 시행착오 끝에, 다음과 같이 사용 방법을 확인할 수 있었다.

아래 코드에서 broadcaststack은 저장소 이름이고, 934/9에서 934는 Gerrit의 Change number(리뷰요청번호), 9는 Patchset number 이다.

$ repo download broadcaststack 934/9
From ssh://gerrit.mycompany.net:29418/broadcaststack
 * branch              refs/changes/34/934/9 -> FETCH_HEAD
HEAD is now at 49a307e6 test

 

Jenkins script에서 특정 디렉토리로 이동해서 git fetch하던 방식을, 훨씬 단순하고도 직관적으로 개선할 수 있었다.

그리고, 다시 Patchset을 적용하기 전으로 돌아가기 위해서는 단순히 repo sync를 해주면 되었다.

# AS-IS
cd vendor/google/tv/broadcaststack
git fetch "ssh://gerrit@gerrit.mycompany.net:29418/broadcaststack" ${GERRIT_REFSPEC} && git checkout FETCH_HEAD


# TO-BE
repo download $GERRIT_PROJECT $GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER

 

'Gerrit' 카테고리의 다른 글

Gerrit 3.1.10 - 이전 설치 ( Migration, Docker )  (0) 2022.05.16
Gerrit 3.5.1 - 설치 ( Docker )  (0) 2022.05.11
Gerrit - LDAP 설정  (0) 2022.05.03
Gerrit - 설치 ( Standalone )  (0) 2022.04.22
Gerrit - 설치 ( Quickstart )  (0) 2022.04.20

Reference

기존 Jenkins Slave로 사용하는 서버의 저장공간이 부족하여, 다른 서버에 Jenkins Slave를 하나 추가하기로 하였다.

아래 작업 내용은 Slave 서버에서만 설정해주면 된다.

 

우선 Slave 서버에 계정을 추가한다.

sudo adduser jenkins_slave

새로 생성한 계정으로 로그인 후에, 기존 서버내 ~/.ssh 디렉토리를 복사하였다.

scp -r ??.??.???.??:/home/jenkins_slave/.ssh .

그리고, Master ( Built-in Node )에서 Slave로 접근할 수 있도록, Master의 공개키를 ~/.ssh/authorized_keys 파일에 추가한다.

cat >> ~/.ssh/authorized_keys

 

Jenkins Master의 Jenkins Dashboard > Jenkins 관리 > 노드 관리 로 이동.

 

신규노드 > New node 에서 값 설정 > Create

 

Host 설정 관련 내용을 설정한다.

Credentials은 기존을 이용하는 경우는 해당 item을 선택하고,

신규 Credentials 추가가 필요한 경우에는 Credentials > Add 선택한다.

내 경우에는 단순히 노드 추가이므로 기존 Credentials을 선택하였다.

 

Credentials 추가하는 경우에 다음 내용을 설정한다.

  • Username : Master 서버의 계정
  • Private Key : Master 서버의 private key ( id_rsa ) 추가

 

이상을 완료하면 노드가 추가된 것을 확인할 수 있다.

Makefile 강좌를 다시 따라하였다. 강좌는 https://wiki.kldp.org/KoreanDoc/html/GNU-Make/GNU-Make.html#toc1 에 있다. 강좌 중에 gccmakedep 부분은 http://forum.falinux.com/zbxe/?document_srl=494921&mid=lecture_tip&sort_index=regdate&order_type=desc 로 대체하였다.



+ Recent posts