gitlab cicd自动打包发布到私有仓库
首先安装gitlab runner查看安装说明sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64# Give it permission to executesudo
·
首先安装gitlab runner
查看安装说明
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# Give it permission to execute
sudo chmod +x /usr/local/bin/gitlab-runner
# Create a GitLab Runner user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
# Install and run as a service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
注册runner
sudo gitlab-runner register --url $GITLABURL --registration-token $REGISTRATION_TOKEN
[root@gitlab ~]# gitlab-runner register --url http://192.168.55.11/ --registration-token GR1348941iEsdsdq12f:%wea
Runtime platform arch=amd64 os=linux pid=221844 revision=bd40e3da version=14.9.1
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
[http://192.168.55.11/]:
Enter the registration token:
[GR1348941iEsdsdq12f:%wea]:
Enter a description for the runner:
[gitlab]: k8s #任意输入
Enter tags for the runner (comma-separated):
k8s-git #任意输入
Enter optional maintenance note for the runner:
Registering runner... succeeded runner=GR134894
Enter an executor: kubernetes, custom, parallels, shell, ssh, virtualbox, docker+machine, docker-ssh+machine, docker, docker-ssh:
shell #此处可根据自己情况进行选择docker
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
注册完成后可看到新创建的Runner
完成runner创建后可进行cicd编辑
在使用shell模式时,需要在gitlab服务器上安装git及maven,在代码库的pom.xml上添加私有仓库地址,需要和maven下settings.xml相对应
<distributionManagement>
<!--正式版本-->
<repository>
<!-- nexus服务器中用户名:在settings.xml中<server>的id-->
<id>maven-releases</id>
<!-- 这个名称自己定义 -->
<name>Releases</name>
<url>http://192.168.55.22/repository/maven-releases/</url>
</repository>
<!--快照版本 -->
<snapshotRepository>
<id>maven-snapshots</id>
<name>Snapshot</name>
<url>http://192.168.55.22/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
settingx.xml配置
<?xml version="1.0"?>
<settings>
<mirrors>
<mirror>
<id>maven-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.55.22/repository/maven-public/</url>
</mirror>
<mirror>
<id>maven-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.55.22/repository/maven-public/</url>
</mirror>
</mirrors>
<servers>
<server>
<id>maven-releases</id>
<username>nexususer</username>
<password>Ne3#k4%l</password>
</server>
<server>
<id>maven-snapshots</id>
<username>nexususer</username>
<password>Ne3#k4%l</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>maven-releases</id>
<url>http://192.168.55.22/repository/maven-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>maven-snapshots</id>
<url>http://192.168.55.22/repository/maven-snapshots/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-releases</id>
<url>http://192.168.55.22/repository/maven-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>maven-snapshots</id>
<url>http://192.168.55.22/repository/maven-snapshots/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
gitlab-ci.yml配置内容,仅master分支触发
stages:
- build
job_build:
stage: build
script:
- echo "start mvn build!!!"
- echo $CI_COMMIT_TAG
- mvn versions:set -DnewVersion=$CI_COMMIT_TAG
- mvn clean deploy
only:
- master
tags:
- mvn #此处为Runner的tag,可用于指定Runner
更多推荐
已为社区贡献2条内容
所有评论(0)