development

Hudson / Jenkins 구성 파일을 소스 제어로 유지하는 방법이 있습니까?

big-blog 2020. 6. 26. 07:44
반응형

Hudson / Jenkins 구성 파일을 소스 제어로 유지하는 방법이 있습니까?


나는 Hudson / Jenkins를 처음 사용하고 Hudson의 구성 파일을 소스 제어로 확인하는 방법이 있는지 궁금합니다.

UI에서 '구성 저장'이라고 표시된 일부 버튼을 클릭하고 Hudson 구성 파일을 소스 제어에 체크인하도록하는 것이 이상적입니다.


가장 유용한 답변

SCM Sync 구성 플러그인 이라는 플러그인이 있습니다.


원래 답변

비슷한 질문에 대한 내 대답살펴보십시오 . 기본 아이디어는 filesystem-scm-plugin 을 사용하여 xml 파일의 변경 사항을 감지하는 것입니다. 두 번째 부분은 SVN의 변경 사항을 커밋하는 것입니다.

편집 : 변경에 대한 사용자를 결정하는 방법을 찾으면 알려주십시오.

편집 2011-01-10 한편 새로운 플러그인 인 SCM Sync 구성 플러그인이 있습니다. 현재는 subversion 및 git에서만 작동하지만 더 많은 리포지토리에 대한 지원이 계획되어 있습니다. 0.0.3 버전부터 사용하고 있으며 지금까지는 잘 작동했습니다.


Vogella는 최근 (2014 년 1 월 OP의 질문에 대한 2010 년 1 월과 비교) 다른 점을 가지고 있습니다. SCM 동기화 구성 플러그인 이 많은 커밋을 생성 할 수
있다고 생각하십시오 . 따라서 플러그인과 자동화 된 프로세스에 의존하는 대신 동일한 기능을 수동으로 관리합니다.

Git에 Jenkins의 작업 정보 저장

커밋의 양이 약간 압도적이라는 것을 알았으므로 커밋을 수동으로 제어하고 Jenkins 구성이 아닌 작업 정보 만 저장하기로 결정했습니다.
이를 위해 Jenkins 작업 디렉토리 (Ubuntu :)로 전환 /var/lib/jenkins/jobs하고“ git init”명령을 수행하십시오 .

.gitignoreGit 작업 정보 만 저장하기 위해 다음 파일을 만들었습니다 .

builds/
workspace/
lastStable
lastSuccessful
nextBuildNumber
modules/
*.log

이제 원하는대로 변경 사항을 추가하고 커밋 할 수 있습니다.
또한 Git 리포지토리에 다른 원격 장치를 추가하면 구성을 다른 서버로 푸시 할 수 있습니다.

Alberto는 실제로 ( $JENKINS_HOME) 도 추가 할 것을 권장합니다 .

  • 젠킨스 자신의 설정 ( config.xml),
  • 젠킨스 플러그인 설정 ( hudson*.xml) 및
  • 사용자 설정 ( users/*/config.xml)

Git으로 구성을 수동으로 관리하려면 다음 .gitignore 파일이 도움이 될 수 있습니다.

# Miscellaneous Hudson litter
*.log
*.tmp
*.old
*.bak
*.jar
*.json

# Generated Hudson state
/.owner
/secret.key
/queue.xml
/fingerprints/
/shelvedProjects/
/updates/

# Tools that Hudson manages
/tools/

# Extracted plugins
/plugins/*/

# Job state
builds/
workspace/
lastStable
lastSuccessful
nextBuildNumber

자세한 내용은 이 GitHub Gist이 블로그 게시물 을 참조하십시오.


원하는 것을 정확하게 수행 하는 새로운 SCM 동기화 구성 플러그인 이 있습니다.

SCM 동기화 구성 Hudson 플러그인은 다음 두 가지 주요 기능을 목표로합니다.

  • SCM 저장소와 config.xml (및 기타 리소스) 허드슨 파일을 동기화 된 상태로 유지
  • 커밋 메시지를 사용하여 모든 파일의 변경 사항 및 작성자 추적

실제로 이것을 시도하지는 않았지만 유망한 것으로 보입니다.


Jenkins 홈 폴더 (예 :) 에서 구성 파일을 찾을 수 있습니다 /var/lib/jenkins.

VCS에 보관하려면 먼저 Jenkins ( sudo su - jenkins) 로 로그인 하고 git 자격 증명을 만드십시오.

git config --global user.name "Jenkins"
git config --global user.email "jenkins@example.com"

그런 다음 다음과 같은 기본 파일을 초기화하고 추가하고 커밋하십시오.

git init
git add config.xml jobs/ .gitconfig
git commit -m'Adds Jenkins config files' -a

또한 .gitignore다음 파일로 작성 하여 무시하십시오 (필요에 따라 사용자 정의).

# Git untracked files to ignore.

# Cache.
.cache/

# Fingerprint records.
fingerprints/

# Working directories.
workspace/

# Secret files.
secrets/
secret.*
*.enc
*.key
users/
id_rsa

# Plugins.
plugins/

# State files.
*.state

# Job state files.
builds/
lastStable
lastSuccessful
nextBuildNumber

# Updates.
updates/

# Hidden files.
.*
# Except git config files.
!.git*
!.ssh/

# User content.
userContent/

# Log files.
logs/
*.log

# Miscellaneous litter
*.tmp
*.old
*.bak
*.jar
*.json
*.lastExecVersion

그런 다음 추가하십시오 git add .gitignore..

완료되면 작업 구성 파일을 추가 할 수 있습니다 (예 :

shopt -s globstar
git add **/config.xml
git commit -m'Added job config files' -a

마지막으로 필요한 경우 다른 파일을 추가하고 커밋 한 다음 구성 파일을 유지하려는 원격 저장소로 파일을 푸시하십시오.


Jenkins 파일이 업데이트되면 파일을 다시로드하거나 ( 디스크에서 구성 다시로드 ) reload-configurationJenkins CLI에서 실행 해야합니다 .


내가 선호하는 방법은 실제로 VCS에 포함하려는 구성 파일을 제외하고 Jenkins 홈 폴더의 모든 것을 제외하는 것입니다 . .gitignore내가 사용 하는 파일 은 다음과 같습니다 .

*
!.gitignore
!/jobs/*/*.xml
!/*.xml
!/users/*/config.xml
!*/

This ignores everything (*) except (!) .gitignore itself, the jobs/projects, the plugin and other important and user configuration files.

It's also worth considering to include the plugins folder. Annoyingly updated plugins should be included...

Basically this solution makes it easier for future Jenkins/Hudson updates because new files aren't automatically in scope. You just get on the screeen what you really want.


A more accurate .gitignore, inspired by the reply from nepa:

*
!.gitignore
!/jobs/
!/jobs/*/
/jobs/*/*
!/jobs/*/config.xml
!/users/
!/users/*/
/users/*/*
!/users/*/config.xml
!/*.xml

It ignores everything except for .xml config files and .gitignore itself. (the difference to nepa's .gitignore is that it doesn't "unignore" all top-level directories (!*/) like logs/, cache/, etc.)


Answer from Mark (https://stackoverflow.com/a/4066654/142207) should work for SVN and Git (although Git configuration did not work for me).

But if you need it to work with Mercurial repo, create a job with following script:

hg remove -A || true
hg add ../../config.xml
hg add ../../*/config.xml
if [ ! -z "`hg status -admrn`" ]; then
    hg commit -m "Scheduled commit" -u fill_in_the@blank.com
    hg push
fi

I've written a plugin that lets you check your Jenkins instructions into source control. Just add a .jenkins.yml file with the contents:

script:
    - make
    - make test

and Jenkins will do it:

enter image description here


I checked in hudson entirely, you could use this as a starting point https://github.com/morkeleb/continuous-delivery-with-hudson

There are benefits to keeping entire hudson in git. All config changes are logged and you can test the testup quite easily on one machine and then update the other machine(s) using git pull.

We used this as a boilerplate for our hudson continuous delivery setup at work.

Regards Morten

참고URL : https://stackoverflow.com/questions/2087142/is-there-a-way-to-keep-hudson-jenkins-configuration-files-in-source-control

반응형