program story

Jenkins Git 플러그인 : 특정 태그를 작성하는 방법?

inputbox 2020. 7. 24. 20:51
반응형

Jenkins Git 플러그인 : 특정 태그를 작성하는 방법?


Jenkins가 지정된 태그를 작성하는 데 문제가 있습니다. 태그는 매개 변수화 된 빌드의 일부이지만 태그를 빌드하기 위해 이것을 git 플러그인으로 전달하는 방법을 모르겠습니다. 이것은 하루 3 시간이 걸렸으며 스택 오버플로에서 마스터에게 패배를 인정했습니다.


"branches to build"매개 변수를 사용하여이를 수행 할 수있었습니다.

Branch Specifier (blank for default): tags/[tag-name]

[tag-name]을 태그 이름으로 바꾸십시오.


Jenkins CI v.1.555, Git Client 플러그인 v.1.6.4 및 Git 플러그인 2.0.4를 사용하면 이러한 답변 중 어느 것도 충분하지 않았습니다.

고정 된 특정 (즉, 매개 변수가없는) 태그 하나에 대해 하나의 Git 리포지토리를 구축하는 작업을 원했습니다. Thilo가 인용 한 다양한 답변과 "Git 태그 작성"블로그 게시물 의 솔루션을 함께 정리해야했습니다 .

  1. 다음을 사용하여 태그를 원격 저장소로 푸시하십시오. git push --tags
  2. 작업의 "Git Repository"섹션에서 "Source Code Management"제목 아래의 "Advanced"를 클릭하십시오.
  3. Refspec 필드에 다음 텍스트를 추가하십시오. +refs/tags/*:refs/remotes/origin/tags/*
  4. "빌드 용 브랜치", "브랜치 지정자"에서 */tags/<TAG_TO_BUILD>( <TAG_TO_BUILD>실제 태그 이름으로 대체) 를 입력하십시오.

나를 위해 Refspec을 추가하는 것이 중요하다는 것이 밝혀졌습니다. 비워두면 git 저장소가 기본적으로 모든 원격 정보를 가져 오는 것처럼 보이지만 Git 플러그인은 그럼에도 불구하고 내 태그를 완전히 찾지 못했습니다. Refspec 필드에 "원격 태그 가져 오기"를 명시 적으로 지정한 경우에만 Git 플러그인이 내 태그를 식별하고 빌드 할 수있었습니다.

2014-5-7 업데이트 : 불행히도이 솔루션에는 Jenkins CI (v.1.555) 및 Git 리포지토리 푸시 알림 메커니즘 -Webhook to Jenkins에 대한 바람직하지 않은 부작용이 발생합니다 : 리포지토리의 모든 분기가 업데이트 될 때마다 푸시하면 태그 빌드 작업도 다시 시작됩니다. 이로 인해 동일한 태그 작업을 반복해서 불필요하게 재 구축하게됩니다. "작업 공간을 사용하여 강제 폴링"옵션을 사용하거나 사용하지 않고 작업을 구성하려고 시도했지만 아무런 영향을 미치지 않는 것 같습니다. Jenkins가 태그 작업에 대해 불필요한 빌드를하지 못하게하는 유일한 방법은 Refspec 필드를 지우는 것입니다 (예 :) +refs/tags/*:refs/remotes/origin/tags/*.

더 우아한 솔루션을 찾는 사람이 있다면 업데이트하여이 답변을 편집하십시오. 예를 들어, refspec +refs/tags/<TAG TO BUILD>:refs/remotes/origin/tags/<TAG TO BUILD>이 별표로 표시 되는 것이 아니라면 이런 일이 발생하지 않을 것 입니다. 그러나 지금은이 솔루션이 효과가 있습니다. 작업이 완료된 후 추가 Refspec을 제거하면됩니다.


Jenkins에게 Ref 이름으로 빌드하도록 지시 할 수 없습니까? 그렇다면

refs/tags/tag-name

Jenkins와 Hudson에 대한 모든 질문에서 TeamCity로 전환하는 것이 좋습니다. TeamCity가 작동하도록 구성 파일을 편집 할 필요가 없었습니다.


나는 이와 같은 일을했고 그것이 효과가 있었다 :

Source Code Management

 Git    
    Repositories    


 Advance

Name: ref
Refspec : +refs/tags/*:refs/remotes/origin/tags/* 

 Branches to build  
 Branch Specifier (blank for 'any') : v0.9.5.2

여기에 이미지 설명을 입력하십시오

Jenkins 로그에서 태그에서 소스를 가져오고 있음을 확인했습니다.

개정 확인 0b4d6e810546663e931cccb45640583b596c24b9(v0.9.5.2)


If you are using Jenkins pipelines and want to checkout a specific tag (eg: a TAG parameter of your build), here is what you can do:

stage('Checkout') {
  steps {
    checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: 'YOUR_GIT_REPO_URL.git', credentialsId: 'YOUR_GIT_CREDENTIALS_ID' ]], branches: [[name: 'refs/tags/${TAG}']]], poll: false
  }
}

I set the Advanced->Refspec field to refs/tags/[your tag name]. This seems simpler than the various other suggestions for Refspec, but it worked just fine for me.

UPDATE 23/7/2014 - Actually, after further testing, it turns out this didn't work as expected. It appears that the HEAD version was still being checked out. Please undo this as the accepted answer. I ended up getting a working solution by following the post from gotgenes in this thread (30th March). The issue mentioned in that post of unnecessary triggering of builds was not an issue for me, as my job is triggered from an upstream job, not from polling SCM.

UPDATE APR-2018 - Note in the comments that this does work for one person, and agrees with Jenkins documentation.


In a latest Jenkins (1.639 and above) you can:

  1. just specify name of tag in a field 'Branches to build'.
  2. in a parametrized build you can use parameter as variable in a same field 'Branches to build' i.e. ${Branch_to_build}.
  3. you can install Git Parameter Plugin which will provide to you functionality by listing of all available branches and tags.

I was able to get Jenkins to build a tag by setting the Refspec and Branch Specifier as detailed in this blog post.

I also had to set the Repository Name (to "origin" in my case) so that I could reference it in the Refspec (otherwise it would apparently use a randomly generated name).


What I did in the end was:

  • created a new branch jenkins-target, and got jenkins to track that
  • merge from whichever branch or tag I want to build onto the jenkins-target
  • once the build was working, tests passing etc, just simply create a tag from the jenkins-target branch

I'm not sure if this will work for everyone, my project was quite small, not too many tags and stuff, but it's dead easy to do, dont have to mess around with refspecs and parameters and stuff :-)


You can build even a tag type, for example 1.2.3-alpha43, using wildcards:

Refspec: +refs/tags/*:refs/remotes/origin/tags/*

Branch specifier: origin/tags/1.2.3-alpha*

You can also tick "Build when a change is pushed to GitHub" to trigger the push, but you have to add "create" action to the webhook


Jenkins에서 "Build with parameters"옵션을 사용하는 답변을 보지 못했기 때문에 여기에 2 센트를 추가하십시오.

여기서는 프로젝트 starwars_api에 Jenkins CI 브라우저 콘솔을 사용하고 있으며 값이 refs / tags / tag-name 인 "Build with parameters"를 사용하여 직접 빌드 할 수있었습니다.

  1. "매개 변수로 빌드"옵션을 선택하십시오.
  2. 상자에 "refs / tags / tag_142"로 값을 추가하십시오 (예를 들어 tag_name = tag_142).

심판 태그 이름으로 빌드

참고 URL : https://stackoverflow.com/questions/10195900/jenkins-git-plugin-how-to-build-specific-tag

반응형