软件包与镜像库
11.7.1. Maven 仓库
项目目录下面创建 ci_settings.xml 文件
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"> <servers> <server> <id>gitlab-maven</id> <configuration> <httpHeaders> <property> <name>Job-Token</name> <value>${env.CI_JOB_TOKEN}</value> </property> </httpHeaders> </configuration> </server> </servers> </settings>
修改 pom.xml 文件添加下面内容
<repositories> <repository> <id>gitlab-maven</id> <url>${env.CI_API_V4_URL}/projects/${env.CI_PROJECT_ID}/packages/maven</url> </repository> </repositories> <distributionManagement> <repository> <id>gitlab-maven</id> <url>${CI_API_V4_URL}/projects/${env.CI_PROJECT_ID}/packages/maven</url> </repository> <snapshotRepository> <id>gitlab-maven</id> <url>${CI_API_V4_URL}/projects/${env.CI_PROJECT_ID}/packages/maven</url> </snapshotRepository> </distributionManagement>
修改 .gitlab-ci.yml 添加 Maven 部署命令
Docker 执行器
deploy: image: maven:3.6-jdk-11 script: - 'mvn deploy -s ci_settings.xml' only: - main
Shell 执行器
deploy: script: - 'mvn deploy -s ci_settings.xml' only: - main
Maven 部署的软件包
|
进入查看详情
|
11.7.1.1. 将已存在的 JAR 文件部署到 Maven 仓库
package: stage: deploy variables: GIT_STRATEGY: none script: - mvn deploy:deploy-file -DrepositoryId=gitlab-maven -Durl=http://registry.netkiller.cn/api/v4/projects/14/packages/maven -Dpackaging=jar -Dfile=lib/cfca.jar -DgroupId=cn.netkiller -DartifactId=cfca -Dversion=1.0.0 -Dmaven.test.skip=true -s .ci_settings.xml - mvn deploy:deploy-file -DrepositoryId=gitlab-maven -Durl=http://registry.netkiller.cn/api/v4/projects/14/packages/maven -Dpackaging=jar -Dfile=lib/ra-toolkit-3.6.28.2.jar -DgroupId=cn.netkiller -DartifactId=ra-toolkit -Dversion=3.6.28.2 -Dmaven.test.skip=true -s .ci_settings.xml - mvn deploy -s .ci_settings.xml -Dmaven.test.skip=true when: manual allow_failure: true only: - testing
11.7.2. Python Pypi 仓库
11.7.2.1. 个人访问令牌
创建访问令牌
|
|
提示 |
---|---|
需要勾选 ☑️ api, read_api, read_registry, write_registry 四个授权️ |
|
将令牌复制出来保存好
11.7.2.2. 手工上传包
创建或编辑 ~/.pypirc 文件
[distutils] index-servers = gitlab [gitlab] repository = https://gitlab.example.com/api/v4/projects/<project_id>/packages/pypi username = <your_personal_access_token_name> password = <your_personal_access_token>
用户和密码,可以使用个人访问令牌、部署令牌和 Gitlab 用户密码
<project_id> 替换成你的项目URL 或者 项目 ID 例如我的项目地址是:http://registry.netkiller.cn/netkiller.cn/python.netkiller.cn/-/packages repository = https://gitlab.example.com/api/v4/projects/netkiller.cn%2Fpython.netkiller.cn/packages/pypi 将 “/” 替换成 “%2F”
查看项目 ID
|
下面是我