You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置Jenkins向Artifactory发布Maven制品的后续步骤及POM修改咨询

Hey there! Let's break down exactly what you need to finish setting up your Jenkins build to publish artifacts to Artifactory, including whether you need to tweak your POM.xml.

1. First, Lock Down Artifactory Credentials in Jenkins

You’ve added the repo URL, but Jenkins needs permission to push artifacts to Artifactory. Here’s how to set that up:

  • Head to Manage Jenkins > Manage Credentials (the "System" domain usually works best for shared credentials).
  • Add a new Username with password credential: use your Artifactory username and either your password or API key (API keys are more secure, so prefer that if you can). Give it a memorable ID like artifactory-deploy-creds so you can reference it later.
  • Go back to your Maven build task, find the Artifactory plugin configuration section, and link this credential to your already-configured Artifactory server URL.

2. Configure the Jenkins Build Step to Publish

Don’t use the regular "Invoke top-level Maven targets" step—instead, use the Invoke Artifactory Maven 3 step that comes with the plugin. Here’s what to set:

  • In the "Goals and options" field, enter your build + publish command: clean install deploy (the deploy goal is critical here—it tells Maven to push artifacts to the repository).
  • Switch to the Artifactory Deployment tab:
    • Check the box for "Deploy artifacts to Artifactory".
    • Select your Target Repository: pick your snapshot repo if you’re publishing SNAPSHOT versions, or your release repo for stable builds.
    • Optional but recommended: Set a Build Name and Build Number (you can use Jenkins variables like ${JOB_NAME} and ${BUILD_NUMBER}) so Artifactory tracks which build each artifact came from.

3. Yes, You Do Need to Modify Your POM.xml

Maven needs to know where to send artifacts, so add these sections to your POM:

Distribution Management (Required for Publishing)

This tells Maven exactly which Artifactory repos to deploy to:

<distributionManagement>
    <repository>
        <id>artifactory-release-repo</id>
        <url>https://your-artifactory-url/libs-release-local</url>
    </repository>
    <snapshotRepository>
        <id>artifactory-snapshot-repo</id>
        <url>https://your-artifactory-url/libs-snapshot-local</url>
    </snapshotRepository>
</distributionManagement>

Pro tip: The <id> values here need to match the ID of the credential you created in Jenkins (or the server ID in your Maven settings.xml if you use that instead).

Repositories (For Pulling Dependencies)

If your project relies on private artifacts stored in Artifactory, add this to pull them during the build:

<repositories>
    <repository>
        <id>artifactory-release-repo</id>
        <url>https://your-artifactory-url/libs-release</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
    <repository>
        <id>artifactory-snapshot-repo</id>
        <url>https://your-artifactory-url/libs-snapshot</url>
        <releases><enabled>false</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
</repositories>

4. Optional: Use Maven Settings.xml Instead (If You Prefer)

If you don’t want to hardcode repo URLs in your POM (good for open-source projects or shared POMs), you can configure a Maven settings.xml in Jenkins:

  • Go to Manage Jenkins > Global Tool Configuration, find your Maven installation, and add a custom settings.xml.
  • Inside the settings, add <servers> (matching your Artifactory credentials) and <mirrors> pointing to Artifactory. This way, your POM doesn’t need the distributionManagement section—Maven will use the settings instead.

5. Test It Out!

Trigger a manual build in Jenkins and watch the console output. Look for lines like "Deploying artifact to Artifactory" to confirm it’s working. Then log into Artifactory, navigate to your target repo, and check that your artifacts (JARs, WARs, POMs) are there. You should also see the build listed in Artifactory’s Builds section if you configured the build name/number.

内容的提问来源于stack exchange,提问作者MK dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:36:14