summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Busatto <fabio@gitlab.com>2017-08-03 01:06:19 +0000
committerFabio Busatto <fabio@gitlab.com>2017-08-03 01:06:19 +0000
commit135e37db6a20b4ee97d7529c5c2636045373812b (patch)
tree5330e0a9d8e7d54f179fa2d70432805621dfaea6
parent829a73af1ff0d866633d22ddea673bbf74bb4e30 (diff)
downloadgitlab-ce-135e37db6a20b4ee97d7529c5c2636045373812b.tar.gz
Update index.md
-rw-r--r--doc/articles/how_to_use_gitlab_ci_to_deploy_maven_projects_to_artifactory/index.md126
1 files changed, 56 insertions, 70 deletions
diff --git a/doc/articles/how_to_use_gitlab_ci_to_deploy_maven_projects_to_artifactory/index.md b/doc/articles/how_to_use_gitlab_ci_to_deploy_maven_projects_to_artifactory/index.md
index 784676ae8d2..d2061279646 100644
--- a/doc/articles/how_to_use_gitlab_ci_to_deploy_maven_projects_to_artifactory/index.md
+++ b/doc/articles/how_to_use_gitlab_ci_to_deploy_maven_projects_to_artifactory/index.md
@@ -1,55 +1,43 @@
+# How to deploy Maven projects to Artifactory with GitLab CI/CD
+
> **Article [Type](../../development/writing_documentation.html#types-of-technical-articles):** tutorial ||
> **Level:** intermediary ||
> **Author:** [Fabio Busatto](https://gitlab.com/bikebilly) ||
> **Publication date:** AAAA/MM/DD
-## Index
-
-- [Introduction](#introduction)
-
-- [Create the simple Maven dependency](#create-the-simple-maven-dependency)
- - [Get the sources](#get-the-sources)
- - [Configure Artifactory deployment](#configure-artifactory-deployment)
- - [Configure GitLab Continuous Integration for `simple-maven-dep`](#configure-gitlab-continuous-integration-for-simple-maven-dep)
-
-- [Create the main Maven application](#create-the-main-maven-application)
- - [Prepare the application](#prepare-the-application)
- - [Configure the Artifactory repository location](#configure-the-artifactory-repository-location)
- - [Configure GitLab Continuous Integration for `simple-maven-app`](#configure-gitlab-continuous-integration-for-simple-maven-app)
-
-- [Conclusion](#conclusion)
-
## Introduction
-In this article, we're going to see how we can leverage the power of [GitLab Continuous Integration](https://about.gitlab.com/features/gitlab-ci-cd/) to build a [Maven](https://maven.apache.org/) project, deploy it to [Artifactory](https://www.jfrog.com/artifactory/) and then use it from another Maven application as a dependency.
+In this article, we will show how you can leverage the power of [GitLab CI/CD](https://about.gitlab.com/features/gitlab-ci-cd/)
+to build a [Maven](https://maven.apache.org/) project, deploy it to [Artifactory](https://www.jfrog.com/artifactory/), and then use it from another Maven application as a dependency.
-We're going to create two different projects:
+You'll create two different projects:
- `simple-maven-dep`: the app built and deployed to Artifactory (available at https://gitlab.com/gitlab-examples/maven/simple-maven-dep)
- `simple-maven-app`: the app using the previous one as a dependency (available at https://gitlab.com/gitlab-examples/maven/simple-maven-app)
-We assume that we already have a GitLab account on [GitLab.com](https://gitlab.com/), and that we know the basic usage of CI.
-We also assume that an Artifactory instance is available and reachable from the Internet, and that we've valid credentials to deploy on it.
+We assume that you already have a GitLab account on [GitLab.com](https://gitlab.com/), and that you know the basic usage of GitLab CI/CD.
+We also assume that an Artifactory instance is available and reachable from the internet, and that you have valid credentials to deploy on it.
## Create the simple Maven dependency
-#### Get the sources
+### Get the sources
-First of all, we need an application to work with: in this specific case we're going to make it simple, but it could be any Maven application. This will be our dependency we want to package and deploy to Artifactory, in order to be available to other projects.
+First of all, you need an application to work with: in this specific it is a simple one, but it could be any Maven application.
+This will be the dependency you want to package and deploy to Artifactory, in order to be available to other projects.
-For this article we'll use a Maven app that can be cloned from `https://gitlab.com/gitlab-examples/maven/simple-maven-dep.git`, so let's login into our GitLab account and create a new project
-with **Import project from ➔ Repo by URL**. Let's make it `public` so anyone can contribute!
+For this article you'll use a Maven app that can be cloned from `https://gitlab.com/gitlab-examples/maven/simple-maven-dep.git`,
+so log in to your GitLab account and create a new project with **Import project from ➔ Repo by URL**.
This application is nothing more than a basic class with a stub for a JUnit based test suite.
-It exposes a method called `hello` that accepts a string as input, and prints an hello message on the screen.
+It exposes a method called `hello` that accepts a string as input, and prints a hello message on the screen.
-The project structure is really simple, and we're mainly interested in these two resources:
+The project structure is really simple, and you should consider these two resources:
- `pom.xml`: project object model (POM) configuration file
- `src/main/java/com/example/dep/Dep.java`: source of our application
-#### Configure Artifactory deployment
+### Configure Artifactory deployment
-The application is ready to use, but we need some additional steps for deploying it to Artifactory:
-1. login to Artifactory with your user's credentials
+The application is ready to use, but you need some additional steps to deploy it to Artifactory:
+1. log in to Artifactory with your user's credentials
2. from the main screen, click on the `libs-release-local` item in the **Set Me Up** panel
3. copy to clipboard the configuration snippet under the **Deploy** paragraph
4. change the `url` value in order to have it configurable via secret variables
@@ -66,11 +54,14 @@ The snippet should look like this:
</distributionManagement>
```
-Now let's copy the snippet in the `pom.xml` file for our project, just after the `dependencies` section. Easy!
+Now copy the snippet in the `pom.xml` file for your project, just after the `dependencies` section. Easy!
-Another step we need to do before we can deploy our dependency to Artifactory is to configure authentication data. It is a simple task, but Maven requires it to stay in a file called `settings.xml` that has to be in the `.m2` subfolder in the user's homedir. Since we want to use GitLab Runner to automatically deploy the application, we should create the file in our project home and set a command line parameter in `.gitlab-ci.yml` to use our location instead of the default one.
+Another step you need to do before you can deploy the dependency to Artifactory is to configure authentication data.
+It is a simple task, but Maven requires it to stay in a file called `settings.xml` that has to be in the `.m2` subfolder in the user's homedir.
+Since you want to use GitLab Runner to automatically deploy the application, you should create the file in the project home
+and set a command line parameter in `.gitlab-ci.yml` to use the custom location instead of the default one.
-For this scope, let's create a folder called `.m2` in the root of our repo. Inside we must create a file named `settings.xml` and copy the following text in it.
+For this scope, create a folder called `.m2` in the root of the repo. You must create a file named `settings.xml` there, and copy the following text into it.
```xml
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
@@ -88,21 +79,19 @@ For this scope, let's create a folder called `.m2` in the root of our repo. Insi
>**Note**:
`username` and `password` will be replaced by the correct values using secret variables.
-We should remember to commit all the changes to our repo!
+Remember to commit all the changes to the repo!
-#### Configure GitLab Continuous Integration for `simple-maven-dep`
+### Configure GitLab CI/CD for `simple-maven-dep`
-Now it's time we set up GitLab CI to automatically build, test and deploy our dependency!
+Now it's time we set up GitLab CI/CD to automatically build, test and deploy the dependency!
-First of all, we should remember that we need to setup some secret variable for making the deploy happen, so let's go in the **Settings ➔ Pipelines**
+First of all, remember to set up secret variables for your deployment. Navigate to your project's **Settings > Pipelines** page
and add the following secret variables (replace them with your current values, of course):
- **MAVEN_REPO_URL**: `http://artifactory.example.com:8081/artifactory` (your Artifactory URL)
- **MAVEN_REPO_USER**: `gitlab` (your Artifactory username)
- **MAVEN_REPO_PASS**: `AKCp2WXr3G61Xjz1PLmYa3arm3yfBozPxSta4taP3SeNu2HPXYa7FhNYosnndFNNgoEds8BCS` (your Artifactory Encrypted Password)
-Now it's time to define stages in our `.gitlab-ci.yml` file: once pushed to our repo it will instruct the GitLab Runner with all the needed commands.
-
-Let's see the content of the file:
+Now it's time to define jobs in `.gitlab-ci.yml` file: once pushed to the repo it will instruct the GitLab Runner with all the needed commands.
```yaml
image: maven:latest
@@ -134,18 +123,17 @@ deploy:
- master
```
-We're going to use the latest Docker image publicly available for Maven, which already contains everything we need to perform our tasks.
-Environment variables are set to instruct Maven to use the homedir of our repo instead of the user's home.
-Caching the `.m2/repository` folder, where all the Maven files are stored, and the `target` folder, that is the location where our application will be created,
-is useful in order to speed up the process: Maven runs all its phases in a sequential order, so executing `mvn test` will automatically run `mvn compile` if needed,
-but we want to improve performances by caching everything that has been already created in a previous stage.
+It uses the latest Docker image for Maven, which already contains everything you need to perform all the tasks.
+Environment variables are set to instruct Maven to use the `homedir` of the repo instead of the user's home.
+Caching the .m2/repository folder (where all the Maven files are stored), and the target folder (where our application will be created), will be useful for speeding up the process
+by running all Maven phases in a sequential order, therefore, executing `mvn test` will automatically run `mvn compile` if necessary.
Both `build` and `test` jobs leverage the `mvn` command to compile the application and to test it as defined in the test suite that is part of the repository.
Deploy to Artifactory is done as defined by the secret variables we set up earlier.
-The deployment occurs only if we're pushing or merging to `master` branch, so development versions are tested but not published.
+The deployment occurs only if we're pushing or merging to `master` branch, so that the development versions are tested but not published.
-Done! We've now our changes in the GitLab repo, and a pipeline has already been started for this commit. Let's go to the **Pipelines** tab and see what happens.
-If we've no errors, we can see some text like this at the end of the `deploy` job output log:
+Done! Now you have all the changes in the GitLab repo, and a pipeline has already been started for this commit. In the **Pipelines** tab you can see what's happening.
+If the deployment has been successful, the deploy job log will output:
```
[INFO] ------------------------------------------------------------------------
@@ -156,22 +144,22 @@ If we've no errors, we can see some text like this at the end of the `deploy` jo
```
>**Note**:
-the `mvn` command downloads a lot of files from the Internet, so you'll see a lot of extra activity in the log the first time you run it.
+the `mvn` command downloads a lot of files from the internet, so you'll see a lot of extra activity in the log the first time you run it.
-Wow! We did it! Checking in Artifactory will confirm that we've a new artifact available in the `libs-release-local` repo.
+Yay! You did it! Checking in Artifactory will confirm that you have a new artifact available in the `libs-release-local` repo.
## Create the main Maven application
-#### Prepare the application
+### Prepare the application
-Now that we've our dependency available on Artifactory, we want to use it!
+Now that you have the dependency available on Artifactory, you want to use it!
-Let's create another application by cloning the one we can find at `https://gitlab.com/gitlab-examples/maven/simple-maven-app.git`, and make it `public` too!
+Create another application by cloning the one you can find at `https://gitlab.com/gitlab-examples/maven/simple-maven-app.git`.
If you look at the `src/main/java/com/example/app/App.java` file you can see that it imports the `com.example.dep.Dep` class and calls the `hello` method passing `GitLab` as a parameter.
-Since Maven doesn't know how to resolve the dependency, we need to modify the configuration.
-Let's go back to Artifactory, and browse the `libs-release-local` repository selecting the `simple-maven-dep-1.0.jar` file.
-In the **Dependency Declaration** section of the main panel we can copy the configuration snippet:
+Since Maven doesn't know how to resolve the dependency, you need to modify the configuration.
+Go back to Artifactory, and browse the `libs-release-local` repository selecting the `simple-maven-dep-1.0.jar` file.
+In the **Dependency Declaration** section of the main panel you can copy the configuration snippet:
```xml
<dependency>
@@ -181,29 +169,29 @@ In the **Dependency Declaration** section of the main panel we can copy the conf
</dependency>
```
-Let's just copy this in the `dependencies` section of our `pom.xml` file.
+Copy this in the `dependencies` section of the `pom.xml` file.
-#### Configure the Artifactory repository location
+### Configure the Artifactory repository location
-At this point we defined our dependency for the application, but we still miss where we can find the required files.
-We need to create a `.m2/settings.xml` file as we did for our dependency project, and let Maven know the location using environment variables.
+At this point you defined the dependency for the application, but you still miss where you can find the required files.
+You need to create a `.m2/settings.xml` file as you did for the dependency project, and let Maven know the location using environment variables.
-Here is how we can get the content of the file directly from Artifactory:
+Here is how you can get the content of the file directly from Artifactory:
1. from the main screen, click on the `libs-release-local` item in the **Set Me Up** panel
2. click on **Generate Maven Settings**
3. click on **Generate Settings**
3. copy to clipboard the configuration file
4. save the file as `.m2/settings.xml` in your repo
-Now we're ready to use our Artifactory repository to resolve dependencies and use `simple-maven-dep` in our application!
+Now you are ready to use the Artifactory repository to resolve dependencies and use `simple-maven-dep` in your application!
-#### Configure GitLab Continuous Integration for `simple-maven-app`
+### Configure GitLab CI/CD for `simple-maven-app`
-We need a last step to have everything in place: configure `.gitlab-ci.yml`.
+You need a last step to have everything in place: configure `.gitlab-ci.yml`.
-We want to build, test and run our awesome application, and see if we can get the greeting we expect!
+You want to build, test and run your awesome application, and see if you can get the greeting as expected!
-So let's add the `.gitlab-ci.yml` to our repo:
+Add the `.gitlab-ci.yml` to the repo:
```yaml
image: maven:latest
@@ -239,13 +227,11 @@ run:
- mvn $MAVEN_CLI_OPTS exec:java -Dexec.mainClass="com.example.app.App"
```
-And that's it! In the `run` job output log we will find a friendly hello to GitLab!
+And that's it! In the `run` job output log you will find a friendly hello to GitLab!
## Conclusion
-In this article we covered the basic steps to use an Artifactory Maven repository to automatically publish and consume our artifacts.
+In this article we covered the basic steps to use an Artifactory Maven repository to automatically publish and consume artifacts.
A similar approach could be used to interact with any other Maven compatible Binary Repository Manager.
-You can improve these examples, optimizing the `.gitlab-ci.yml` file to better suit your needs, and adapting to your workflow.
-
-Enjoy GitLab CI with all your Maven projects! \ No newline at end of file
+Obviously, you can improve these examples, optimizing the `.gitlab-ci.yml` file to better suit your needs, and adapting to your workflow. \ No newline at end of file