将Azure构建结果发布到私有Nexus服务器

Posted by Simon Dong on 2019-07-26

0x01 需求

Azure DevOps在使用Pipeline构建完成之后,需要将构建的结果推送到Maven私服上。

0x02 实施

参考: Set up Azure Pipelines and Maven

  1. 生成一个Settings.xml,内容包含Maven私服的登录信息。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
    <server>
    <id>ossrh</id>
    <username>[user]</username>
    <password>[password]</password>
    </server>
    </servers>
    </settings>
  2. settings.xml上传到Azure DevOps的工程中的Pipelines->Library->Secure Files中。并在Pipeline permissions中启用Authorize for use in all pipelines

    1564110787441

  3. 在pipleline构建设置azure-pipelines.yml中加入如下Task

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    - task: DownloadSecureFile@1
    name: settingsxml
    inputs:
    secureFile: 'settings.xml'
    - task: PowerShell@2
    inputs:
    targetType: 'inline'
    script: |
    New-Item -Type Directory -Force "${HOME}/.m2"
    Copy-Item -Force "$(settingsxml.secureFilePath)" "${HOME}/.m2/settings.xml"
    pwsh: true

    1564110949534