GitLab CI supports the creation of multiple builds and evaluates whether each code submission passes tests and impacts on your product.During the construction process, a large number of binary files will be generated, and if these files are not properly managed on a large scale, it will lead to binary file management confusion.To overcome this problem, Artifactory is seamlessly integrated into the GitLab CI build process to better publish and manage these binaries, and caches, publishes your dependent packages, product packages, and build information to Artifactory through JFrog CLI.
This article describes how to integrate GitLab CI with Artifactory to not only parse and deploy binaries, but also get more help from Artifactory's Build Integration feature.
After integrating Artifactory with GitLab CI, you can store and view the following information:
Building modules for information and publishing
- Dependency on Use
- environment variable
- License Summary
- Link to your Jira issue
- Differences between builds
1. Environmental Configuration
- Install Gitlab Runner and configure Gitlab (not covered here)
- Prepare a sample project
https://gitlab.com/guoyunzong/maven-example.git - Create warehouse in Artifact (2 local, 1 remote, 1 virtual): maven-dev-local, maven-pro-local, maven-remote, maven-virtual
- Write a configuration file (maven.conf) in the project directory
version: 1 type: maven resolver: snapshotRepo: maven-virtual releaseRepo: maven-virtual serverID: Default-Server deployer: snapshotRepo: maven-virtual releaseRepo: maven-virtual serverID: Default-Server
Write a configuration file (jira-cli.conf) in the project directory
version: 1 issues: serverID: Default-Server trackerName: JIRA regexp: (.+-[0-9]+)\s-\s(.+) keyGroupIndex: 1 summaryGroupIndex: 2 trackerUrl: http://my-jira.com/issues aggregate: true aggregationStatus: RELEASED
- Configure artifactory environment variables in gitlab, Settings-CI/CD-Variables, such as:
ARTIFACTORY_URL http://192.168.230.32:8081/artifactory ARTIFACTORY_USER admin ARTIFACTORY_PASS password MAVEN_REPO_KEY maven-virtual
2. Write Gitlab CI script and execute build
* Write scripts in the project directory (.gitlab-ci.yml) image: docker:git services: - docker:dind stages: - build build: image: maven:3.5.4-jdk-8-alpine stage: build script: # Install - apk add git # Set the M2_HOME environment variable - export M2_HOME=/usr/share/maven # Download JFrog CLI - curl -fL https://getcli.jfrog.io | sh # Configure Artifactory instance with JFrog CLI - ./jfrog rt config --url=$ARTIFACTORY_URL --user=$ARTIFACTORY_USER --password=$ARTIFACTORY_PASS - ./jfrog rt c show # Mvn clean install - ./jfrog rt mvn "clean install" maven.conf --build-name=gitlabci-maven-artifactory --build-number=$CI_JOB_ID # Collect the environment variables - ./jfrog rt bce gitlabci-maven-artifactory $CI_JOB_ID # Add jira issue - ./jfrog rt bag gitlabci-maven-artifactory $CI_JOB_ID --config jira-cli.conf # Add sonar(optional) - ./jfrog rt sp "maven-dev-local/org/jfrog/test/multi3/3.7-SNAPSHOT/*.war" "qulity.gate.sonarUrl=http://192.168.230.156:9000/dashboard/index/gitlabci-maven-artifactory" # Add properties(optional) - ./jfrog rt sp "maven-dev-local/org/jfrog/test/multi3/3.7-SNAPSHOT/*.war" "deploy.tool=ansible" - ./jfrog rt sp "maven-dev-local/org/jfrog/test/multi3/3.7-SNAPSHOT/*.war" "ip=127.0.0.1" # Pass the build information to Artifactory - ./jfrog rt bp gitlabci-maven-artifactory $CI_JOB_ID # Promote - ./jfrog rt bpr gitlabci-maven-artifactory $CI_JOB_ID maven-pro-local # Xray scan(optional) - ./jfrog rt bs gitlabci-maven-artifactory $CI_JOB_ID --fail=false # Download(optional) - ./jfrog rt dl maven-dev-local/org/jfrog/test/multi3/3.7-SNAPSHOT/multi3-3.7-20191213.050538-8.war all-my-frogs/ when: manual
- Submit the code and enter git commit message in the following format****
HAP-1007 - This is a sample issue
*Perform build (configurable for manual or automatic execution)
CI/CD--Pipelines
* View build output in Job
* issue information in artifactory (click HAP-1007 to link to Jira address)
More exciting content Please WeChat Search Public Number: jfrogchina
More technology sharing can focus on February 20 online class: Artifactory & GitLab CI Continuous Integration Practice
Course introduction
With more and more open source projects, most developers are referencing a large number of third-party dependencies, and the frequency of open source third-party components has increased dramatically.Referencing components already developed by third parties brings great convenience to all our developers, reduces a lot of repetitive work and improves development efficiency.But it also brings us some hidden dangers, because open source does not mean that the software is safe, how to control the security of referencing third-party packages is a problem that enterprises need to pay attention to.
Course Income
This course focuses on how JFrog Xray solves security issues with third-party components.
Topics of this issue
- Introduction of third-party components
- Introduction to Xray
- Xray usage scenarios and practices
Classroom activities
The lecturer will draw a prize before the end of this period
First place: Millet Bluetooth headset
Second place: JFrog new T-shirt
Third place: JFrog new T-shirt
Sign-up link: https://www.bagevent.com/event/6370474