Git 트리거를 사용하여 Jenkins CI를 마스터로 푸시하려면 어떻게해야합니까?
GitHub을 사용하는 프로젝트에 Jenkins-ci를 설정하려고합니다. 적절한 플러그인으로 Jenkins를 이미 설정했습니다. Jenkins가 프로젝트의 누군가가 마스터 할 때마다 빌드 스크립트를 실행하기를 원합니다. 지금까지 누군가가 어디로 든 푸시 할 때마다 빌드가 트리거되도록 너무 설정할 수 있었지만 너무 광범위합니다. Git의 수신 후 서비스 후크 로이 작업을 수행했습니다.
Jenkins Wiki와 몇 가지 자습서를 읽었지만이 특정 세부 정보가 누락되었습니다 ... 폴링과 관련이 있습니까? 아니면 Git 쪽에서 작업을 수행하여 Git master
이 변경 될 때만 Jenkins 만 트리거하도록해야 합니까?
그의 의견에서 gezzed 가 이미 언급했듯이 좋은 해결책이 있습니다 ( Polling은 죽어야합니다 : Jenkins 빌드는 Git hook에서 트리거합니다 ).
Jenkins 작업의 빌드 트리거를 Poll SCM 으로 설정하지만 스케줄을 지정 하지 마십시오 .
URL을 알리기 위해 GitHub 수신 후 트리거 생성
http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>?token=<get token from git to build remotely>
지정된 Git 저장소를 폴링하는 모든 빌드가 트리거됩니다.
그러나 폴링은 실제로 사용 된 분기로 푸시 된 것이 있는지 확인합니다.
완벽하게 작동합니다.
버전 0.5부터 Jenkins 용 GitHub 플러그인 은 변경 사항이 GitHub로 푸시 될 때 빌드를 트리거 할 수 있습니다 .
원격으로 빌드 를 트리거하는 대신 Jenkins 프로젝트 구성을 폴링하여 빌드를 트리거하도록 변경하십시오.
Jenkins는 고정 내부 또는 URL을 기준으로 폴링 할 수 있습니다. 후자는 해당 분기에 대한 변경 사항이 없으면 빌드를 건너 뛰려는 것입니다. 정확한 세부 사항은 설명서에 있습니다. 기본적으로 "Soll 폴링"옵션을 확인하고 일정 섹션을 비워두고 JENKINS_URL / job / name / polling에 도달하도록 원격 URL을 설정하면됩니다.
당신이 확보 젠킨스 환경이 달리있는 경우 하나 잡았다 /build
는 /polling
URL은 인증이 필요합니다. 여기에 지시 사항이 있습니다. 예를 들어 GitHub Post-Receive 후크가로 이동합니다 username:apiToken@JENKIS_URL/job/name/polling
.
들어 GitLab , 다음 단계를 사용 :
- 프로젝트 설정으로 이동 → 웹 후크
Jenkins 프로젝트에서 "지금 빌드"URL을 푸시 이벤트 URL로 입력하십시오.
http://server.com/jenkins/job/project_name/build?delay=0sec
예를 들어- 클릭
Add Web Hook
한 다음test hook
그런 다음 저장소에 커밋 할 때마다 웹 후크가 트리거되고 빌드가 작성됩니다. delete workspace before each build
새 코드의 새로운 사본을 얻을 수 있도록 Jenkins 작업 공간을 설정하십시오 .
Git과 관련이 없지만 아래에서는 Mercurial과 함께 Jenkins 작업 구성에 대해 자세히 설명합니다. 비슷한 문제가있는 사람들에게 도움이 될 수 있습니다.
- URL 트리거 플러그인 설치
- 작업 구성 페이지로 이동하여
Poll SCM
옵션을 선택하십시오 . 값을* * * * *
- 옵션을 확인하십시오 :
[URLTrigger] - Poll with a URL
. 이제 수정 날짜 변경, URL 내용 등과 같은 옵션을 선택할 수 있습니다. - 옵션에서 URL 컨텐츠 변경을 선택하고 첫 번째 옵션을 선택하십시오. –
Monitor change of content
- 변경 사항을 저장하십시오.
이제 몇 가지 테스트 체크인을 통해 Mercurial 저장소의 일부 변경을 트리거하십시오.
SCM 변경 사항을 감지하여 Jenkins 작업이 실행되는지 확인하십시오. Mercurial 변경으로 인해 빌드가 실행되면 텍스트가 표시됩니다 Started by an SCM change
. 그렇지 않으면 수동으로 시작한 사용자입니다.
이것이 도움이되기를 바랍니다 : Git 커밋에서 Jenkins 빌드를 트리거하는 방법
curl을 사용하여 Git이 제공하는 Git 후크를 사용하여 Jenkins 작업을 트리거하면됩니다.
이 명령 curl http://localhost:8080/job/someJob/build?delay=0sec
은 Jenkins 작업을 실행할 수 있습니다. 여기서 Jenkins 작업 someJob
의 이름입니다.
숨겨진 .git 폴더에서 "hooks"폴더를 검색하십시오. "post-commit.sample"파일의 이름을 "post-commit"으로 바꾸십시오. 메모장에서 열고 ": Nothing"줄을 제거한 다음 위의 명령을 붙여 넣습니다.
그게 다야. 커밋을 수행 할 때마다 Git은 파일에 정의 된 커밋 후 명령을 트리거합니다.
코드가 Git 명령 / GUI에서 저장소로 푸시 된 후 Jenkins와의 지속적인 통합 :
- 작업 이름으로 만 Jenkins에서 작업을 작성하고 프로젝트 프리 스타일 유형을 선택하십시오. 를 클릭하십시오 OK. 다음 페이지는 아무 것도 추가하지 않고 그냥 클릭하십시오 Save.
- 소스 코드가있는 로컬 Git 저장소로 이동하여
.git/hooks
폴더를 탐색하십시오 . hooks
폴더는 몇 개의 파일이 포함되어 있습니다. "커밋 후"를 확인하십시오. 없는 경우 파일 확장자없이 "포스트 커밋"파일을 만듭니다.C:\work\test\\.git\hooks\post-commit
아래 명령으로 "commit-commit"파일을 편집하십시오. 로컬 소스 코드 후크 폴더에 있는지 확인하십시오.
curl -u userName:apiToken -X POST http://localhost:8080/jenkins/job/jobName/build?token=apiToken
예:
curl -u admin:f1c55b3a07bb2b69b9dd549e96898384 -X POST http://localhost:8080/jenkins/job/Gitcommittest/build?token=f1c55b3a07bb2b69b9dd549e96898384
5.
userName
: Jenkins 사용자 이름jobName
: 빌드의 작업 이름apiToken
: To get your API token, go to your Jenkins user page (top right in the interface). It is available in the "Configure" menu on the left of the page: "Show API token"Make changes in your source code and commit the code to repository.
Your job,
http://localhost:8080/jenkins/job/Gitcommittest/
, should be building.
You need to specify the branch. By default it listens to anything. See the blog post Hudson: Git and Maven plugins.
Generic Webhook Trigger Plugin can be configured with filters to achieve this.
When configured with
- A variable named
ref
and expression$.ref
. - A filter with text
$ref
and filter expression like^refs/heads/master$
.
Then that job will trigger for every push to master
. No polling.
You probably want more values from the webhook to actually perform the build. Just add more variables, with JSONPath, to pick what you need.
There are some use cases here: https://github.com/jenkinsci/generic-webhook-trigger-plugin/tree/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd
In my current organization, we don't do this in master but do do it on both develop and release/ branches (we are using Git Flow), in order to generate snapshot builds.
As we are using a multi branch pipeline, we do this in the Jenkinsfile with the when{} syntax...
stage {
when {
expression {
branch 'develop'
}
}
}
This is detailed in this blog post: https://jenkins.io/blog/2017/01/19/converting-conditional-to-pipeline/#longer-pipeline
Above answers are correct but i am addressing to them who are newbie here for their simplicity
especially for setting build trigger for pipeline:
Consider you have two Github branches: 1.master, 2.dev, and Jenkinsfile (where pipeline script is written) and other files are available on each branch
Configure new Pipeline project (for dev branch)
##1.Code integration with git-plugin and cron based approach Prerequisite git plugin should be installed and configure it with your name and email
- General section.Check checkbox - 'This project is parameterized’ and add Name-SBRANCH Default Value-'refs/remotes/origin/dev'
- Build triggers section" Check checkbox - 'Poll SCM' and schedule as per need for checking commits e.g. '*/1 * * * *' to check every minute
- Pipeline definition section.Select - Pipeline script from SCM—> select git—> addRepository URL—>add git credentials—> choose advanced—> add Name- origin, RefSpec- '+refs/heads/dev:refs/remotes/origin/dev'(dev is github branch )—> Branches to build - ${SBRANCH} (Parameter name from ref 1st point)—> Script Path—> Jenkinsfile —> Uncheck Lightweightcheckout
- Apply—> save
##2.Code integration: github-plugin and webhook approach Prerequisite Github plugin should be installed and Github server should be configured, connection should be tested if not consider following configuration
Configure Github plugin with account on Jenkins
GitHub section Add Github server if not present API URL: https://api.github.com Credentials: Add secret text (Click add button: select type secret text) with value Personal Access Token (Generate it from your Github accounts—> settings—> developer setting—> personal access token—> add token—> check scopes—> copy the token) Test Connection—> Check whether it is connected to your Github account or not Check checkbox with Manage Hooks In advance sub-section just select previous credential for 'shared secret'
Add webhook if not added to your repository by
- Go to Github Repository setting —> add webhook—> add URL
http://Public_IP:Jenkins_PORT/github-webhook/ - Or if you don't have Public_IP use ngrok. Install, authenticate, get public IP from command ./ngrok http 80(use your jenkins_port) then add webhook —> add URL http://Ngrok_IP/github-webhook/
- Test it by delivering payload from webhook page and check whether you get 200 status or not.
If you have Github Pull requests plugin configure it also with published Jenkins URL.
- General section.Check checkbox - 'Github project' add project URL -(github link ending with '.git/')
- General section.Check checkbox - 'This project is parameterized' and add Name-SBRANCH Default Value-'refs/remotes/origin/dev'
- Build triggers.section.Check checkbox - 'GitHub hook trigger for GITScm polling'
- Pipeline def'n section: Select - Pipeline script from SCM—> select git—> addRepository URL—> add git credentials—>choose advanced —>add Name- origin, RefSpec- '+refs/heads/dev:refs/remotes/origin/dev' (dev is github branch ) —> Branches to build - ${SBRANCH} (Parameter name from ref 1.st point)—> Script Path—> Jenkinsfile—> Uncheck Lightweightcheckout
- Apply—> save
Use the pull request builder plugin: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
It's really straightforward. You can then setup GitHub webhooks to trigger builds.
'Programming' 카테고리의 다른 글
Android 앱의 GridView VS GridLayout (0) | 2020.05.08 |
---|---|
바닥 글이 페이지 하단에 올바르게 고정되도록 (0) | 2020.05.08 |
MySQL의 now () +1 일 (0) | 2020.05.07 |
Angular는 AngularJS $ watch와 동일합니까? (0) | 2020.05.07 |
LINQ Single과 First (0) | 2020.05.07 |