프로호스터 > 블로그 > 관리 > Java 프로젝트를 Maven Central에 업로드하도록 GitLab CI 설정
Java 프로젝트를 Maven Central에 업로드하도록 GitLab CI 설정
이 문서는 GitLab을 사용하여 sonatype 및/또는 Maven 중앙 저장소에 제품을 신속하게 게시해야 하는 Java 개발자를 위한 것입니다. 이 기사에서는 이 문제를 해결하기 위해 gitlab-runner, gitlab-ci 및 maven-plugin을 설정하는 방법에 대해 설명합니다.
우선, 아티팩트 배포를 위해 파이프라인이 저장될 프로젝트를 생성하고 구성해야 합니다. 나는 내 프로젝트를 간단하고 복잡하지 않게 불렀습니다. 배포
저장소를 생성한 후에는 저장소 수정을 위한 접근을 제한해야 합니다.
프로젝트 -> 설정 -> 저장소 -> 보호된 분기로 이동합니다. 모든 규칙을 삭제하고 유지 관리 역할을 가진 사용자에 대해서만 푸시 및 병합할 수 있는 권한이 있는 와일드카드 *가 포함된 단일 규칙을 추가합니다. 이 규칙은 이 프로젝트와 이 프로젝트가 속한 그룹 모두의 모든 사용자에게 적용됩니다.
관리자가 여러 명인 경우 가장 좋은 해결책은 원칙적으로 프로젝트에 대한 액세스를 제한하는 것입니다.
프로젝트 -> 설정 -> 일반 -> 가시성, 프로젝트 기능, 권한으로 이동하여 프로젝트 가시성을 다음으로 설정하세요. 프라이빗 투어.
저는 자체 GitLab Runner를 사용하고 나만 저장소를 수정할 수 있는 액세스 권한을 갖고 있으므로 공개 액세스 프로젝트를 보유하고 있습니다. 글쎄요, 사실 공개 파이프라인 로그에 개인 정보를 표시하는 것은 제 관심사가 아닙니다.
저장소 변경 규칙 강화
프로젝트 -> 설정 -> 리포지토리 -> 푸시 규칙으로 이동하여 커미터 제한 플래그를 설정하고 작성자가 GitLab 사용자인지 확인하세요. 저도 설정 추천드려요 서명 커밋, 서명되지 않은 커밋 거부 플래그를 설정합니다.
다음으로 작업을 실행하도록 트리거를 구성해야 합니다.
프로젝트 -> 설정 -> CI/CD -> 파이프라인 트리거로 이동하여 새 트리거 토큰을 만듭니다.
이 토큰은 프로젝트 그룹의 일반 변수 구성에 즉시 추가될 수 있습니다.
그룹 -> 설정 -> CI/CD -> 변수로 이동하여 변수를 추가하세요. DEPLOY_TOKEN 값에 트리거 토큰이 있습니다.
Runtime platform arch=amd64 os=linux pid=17594 revision=3001a600 version=11.10.0
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab.com/
Please enter the gitlab-ci token for this runner:
REGISTRATION_TOKEN
Please enter the gitlab-ci description for this runner:
[ih1174328.vds.myihor.ru]: Deploy Runner
Please enter the gitlab-ci tags for this runner (comma separated):
deploy
Registering runner... succeeded runner=ZvKdjJhx
Please enter the executor: docker-ssh, parallels, virtualbox, docker-ssh+machine, kubernetes, docker, ssh, docker+machine, shell:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
주자가 등록되어 있는지 확인하세요. gitlab.com으로 이동 -> 배포 프로젝트 -> 설정 -> CI/CD -> 실행자 -> 특정 실행자 -> 이 프로젝트에 대해 활성화된 실행자
스크린
첨가 분리하다 서비스 /etc/systemd/system/gitlab-deployer.service
이 주제는 매우 자세히 설명되어 있습니다. 고골 플렉스 в 스냅샷 및 스테이징 저장소에 아티팩트를 자동으로 서명하고 업로드하도록 Maven 설정, 그래서 플러그인 사용의 몇 가지 뉘앙스를 설명하겠습니다. 얼마나 쉽고 자연스럽게 사용할 수 있는지도 알려드릴게요 nexus-staging-maven-pluginorg.sonatype.oss:oss-parent를 프로젝트의 상위 항목으로 사용하고 싶지 않거나 사용할 수 없는 경우.
메이븐 설치 플러그인
로컬 저장소에 모듈을 설치합니다.
체크섬뿐만 아니라 다른 프로젝트의 솔루션에 대한 로컬 검증에도 매우 유용합니다.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-project</id>
<!-- Если у вас многомодульный проект с деплоем родительского помика -->
<phase>install</phase>
<!-- Явно указываем файлы для локальной установки -->
<configuration>
<file>target/${project.artifactId}-${project.version}.jar</file>
```target/${project.artifactId}-${project.version}-sources.jar</sources>
<pomFile>dependency-reduced-pom.xml</pomFile>
<!-- Принудительное обновление метаданных проекта -->
<updateReleaseInfo>true</updateReleaseInfo>
<!-- Контрольные суммы для проверки целостности -->
<createChecksum>true</createChecksum>
</configuration>
</execution>
</executions>
</plugin>
<repositories>
<repository>
<id>SonatypeNexus</id>
<url>https://oss.sonatype.org/content/groups/staging/</url>
<!-- Не надо указывать флаги snapshot/release для репозитория -->
</repository>
</repositories>
더 많은 장점
넥서스 저장소 작업을 위한 매우 풍부한 대상 목록(mvn help:describe -Dplugin=org.sonatype.plugins:nexus-staging-maven-plugin).
태그가 설정되면 배포 프로젝트의 해당 작업이 자동으로 트리거되어 출시 버전을 nexus(예).
가장 좋은 점은 닫기 릴리스가 넥서스에서 자동으로 실행된다는 것입니다.
[INFO] Performing remote staging...
[INFO]
[INFO] * Remote staging into staging profile ID "9043b43f77dcc9"
[INFO] * Created staging repository with ID "orgtouchbit-1037".
[INFO] * Staging repository at https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/orgtouchbit-1037
[INFO] * Uploading locally staged artifacts to profile org.touchbit
[INFO] * Upload of locally staged artifacts finished.
[INFO] * Closing staging repository with ID "orgtouchbit-1037".
Waiting for operation to complete...
.........
[INFO] Remote staged 1 repositories, finished with success.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Shields4J 1.0.0 .................................... SUCCESS [ 9.603 s]
[INFO] test-core .......................................... SUCCESS [ 3.419 s]
[INFO] Shields4J client ................................... SUCCESS [ 9.793 s]
[INFO] TestNG listener 1.0.0 .............................. SUCCESS [01:23 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:47 min
[INFO] Finished at: 2019-04-21T04:05:46+03:00
[INFO] ------------------------------------------------------------------------
그리고 뭔가 잘못되면 작업이 실패하게 됩니다.
[INFO] Performing remote staging...
[INFO]
[INFO] * Remote staging into staging profile ID "9043b43f77dcc9"
[INFO] * Created staging repository with ID "orgtouchbit-1038".
[INFO] * Staging repository at https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/orgtouchbit-1038
[INFO] * Uploading locally staged artifacts to profile org.touchbit
[INFO] * Upload of locally staged artifacts finished.
[INFO] * Closing staging repository with ID "orgtouchbit-1038".
Waiting for operation to complete...
.......
[ERROR] Rule failure while trying to close staging repository with ID "orgtouchbit-1039".
[ERROR]
[ERROR] Nexus Staging Rules Failure Report
[ERROR] ==================================
[ERROR]
[ERROR] Repository "orgtouchbit-1039" failures
[ERROR] Rule "signature-staging" failures
[ERROR] * No public key: Key with id: (1f42b618d1cbe1b5) was not able to be located on <a href=http://keys.gnupg.net:11371/>http://keys.gnupg.net:11371/</a>. Upload your public key and try the operation again.
...
[ERROR] Cleaning up local stage directory after a Rule failure during close of staging repositories: [orgtouchbit-1039]
[ERROR] * Deleting context 9043b43f77dcc9.properties
[ERROR] Cleaning up remote stage repositories after a Rule failure during close of staging repositories: [orgtouchbit-1039]
[ERROR] * Dropping failed staging repository with ID "orgtouchbit-1039" (Rule failure during close of staging repositories: [orgtouchbit-1039]).
[ERROR] Remote staging finished with a failure: Staging rules failure!
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Shields4J 1.0.0 .................................... SUCCESS [ 4.073 s]
[INFO] test-core .......................................... SUCCESS [ 2.788 s]
[INFO] Shields4J client ................................... SUCCESS [ 3.962 s]
[INFO] TestNG listener 1.0.0 .............................. FAILURE [01:07 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
결과적으로 우리에게 남은 선택은 하나뿐이다. 또는 이 버전을 삭제하거나 게시하세요.
출시 후 일정 시간이 지나면 유물이
주제를 벗어
Maven이 다른 공개 저장소를 색인화한다는 것은 나에게 새로운 계시였습니다.
이전 저장소의 색인을 생성했기 때문에 robots.txt를 업로드해야 했습니다.
다양한 개발 언어에 대한 공개 저장소에 아티팩트를 업로드하기 위한 여러 CI 작업을 구현할 수 있는 별도의 배포 프로젝트입니다.
배포 프로젝트는 외부 간섭으로부터 격리되며 소유자 및 유지 관리 역할을 가진 사용자만 수정할 수 있습니다.
배포 작업만 실행하기 위한 "핫" 캐시가 있는 별도의 특정 실행기.
공개 저장소에 스냅샷/릴리스 버전을 게시합니다.
Maven Central에 게시할 준비가 되었는지 릴리스 버전을 자동으로 확인합니다.
Maven Central에서 "원시" 버전이 자동으로 게시되는 것을 방지합니다.
"클릭 시" 스냅샷 버전을 구축하고 게시합니다.
스냅샷/릴리스 버전을 가져오기 위한 단일 저장소입니다.
Java 프로젝트 빌드/테스트/게시를 위한 일반 파이프라인입니다.
GitLab CI 설정은 언뜻 보기에 그렇게 복잡한 주제가 아닙니다. 턴키 방식으로 CI를 몇 번 설정하는 것만으로도 충분하며 이제 이 문제에 있어서 아마추어와는 거리가 멀습니다. 게다가 GitLab 문서는 매우 중복됩니다. 첫발을 내딛는 것을 두려워하지 마십시오. 걷는 사람의 발걸음 아래에 길이 나타납니다. (누가 말했는지 기억이 나지 않습니다 :)
나는 피드백을 기쁘게 생각합니다.
다음 기사에서는 Shell Runner가 하나만 있는 경우 통합 테스트 작업을 경쟁적으로 실행(docker-compose를 사용하여 테스트 서비스 실행)하도록 GitLab CI를 설정하는 방법을 보여 드리겠습니다.