Use Nexus in Pipelines
This tutorial demonstrates how to use Nexus in pipelines on KubeSphere.
- You need to enable the KubeSphere DevOps System.
- You need to .
- You need to have a GitHub account.
- You need to create a workspace, a DevOps project (for example,
demo-devops
), and a user (for example,project-regular
). This account needs to be invited into the DevOps project with the role ofoperator
. For more information, see .
Hands-on Lab
Go to the Repositories page and you can see that Nexus provides three types of repository.
proxy
: the proxy for a remote repository to download and store resources on Nexus as cache.hosted
: the repository storing artifacts on Nexus.group
: a group of configured Nexus repositories.
- You can click a repository to view its details. For example, click maven-public to go to its details page, and you can see its URL.
Log in to GitHub. Fork to your own GitHub account.
In your own GitHub repository of learn-pipeline-java, click the file
pom.xml
in the root directory.Click to modify the code segment of in the file. Set the
<id>
and use the URLs of your own Nexus repositories.When you finish, click Commit changes at the bottom of the page.
Log in to the KubeSphere web console as
admin
, click Platform in the upper-left corner, and select Cluster Management.Select ConfigMaps under Configuration. On the ConfigMaps page, select
kubesphere-devops-worker
from the drop-down list and clickks-devops-agent
.In the displayed dialog box, scroll down, find the code segment of
<servers>
, and enter the following code:Note
<id>
is the unique identifier you set for your Nexus in step 2.<username>
is your Nexus username.<password>
is your Nexus password. You can also configure aNuGet API Key
on Nexus and use it here for better security.Continue to find the code segment of and enter the following code:
Note
<id>
is the unique identifier you set for your Nexus in step 2.<name>
is the Nexus repository name.<url>
is the URL of your Nexus repository.<mirrorOf>
is the Maven repository to be mirrored. In this tutorial, enter*
to mirror all Maven repositories. For more information, refer to Using Mirrors for Repositories.When you finish, click OK.
Log out of the KubeSphere web console and log back in as
project-regular
. Go to your DevOps project and click Create on the Pipelines page.On the Advanced Settings tab, click Create to use the default settings.
Click the pipeline name to go to its details page and click Edit Jenkinsfile.
In the displayed dialog box, enter the Jenkinsfile as follows. When you finish, click OK.
Note
You need to replace the GitHub repository address with your own. In the command from the step in the stage
deploy to Nexus
,nexus
is the name you set in in the ConfigMap andhttp://135.68.37.85:8081/repository/maven-snapshots/
is the URL of your Nexus repository.
You can see all the stages and steps shown on the graphical editing panels. Click Run to run the pipeline.
After a while, you can see the pipeline status shown as Successful. Click the Successful record to see its details.
You can click View Logs to view the detailed logs.