Configure access credentials for dependency downloads

Updated at:

During a build, your pipeline needs to download dependencies, requiring access credentials for your private repositories. To keep your credentials secure, Flow lets you configure them as environment variables. For credentials that are managed across your entire organization, we recommend using a general variable group instead.

Java

  1. Add the URL, username, and password for your private repository to the settings.xml file. Configure the username and password using environment variables.

    <servers>
      <server>
        <id>rdc-releases</id>
        <username>${MVN_USERNAME}</username>
        <password>${MVN_PASSWORD}</password>
      </server>
      <server>
        <id>rdc-snapshots</id>
        <username>${MVN_USERNAME}</username>
        <password>${MVN_PASSWORD}</password>
      </server>
    </servers>
    <profiles>
      <profile>
        <activation>
          <activeByDefault>true</activeByDefault>
        </activation>
        <id>rdc-private-repo</id>
        <repositories>
          <repository>
            <id>rdc-releases</id>
            <url>https://packages.aliyun.com/maven/repository/2000093-release/</url>
          </repository>
          <repository>
            <id>rdc-snapshots</id>
            <url>https://packages.aliyun.com/maven/repository/2000093-snapshot/</url>
          </repository>
        </repositories>
      </profile>
    </profiles>

    In the code sample, replace the content of the <url> tag with the URL of your private repository.

  2. In your pipeline, configure environment variables for the Maven repository username and password.

    Click the Variables tab in the top navigation bar. In the Configure Variable Group section, add two parameters: MVN_USERNAME and MVN_PASSWORD. Set their default values to your Maven repository username and password, respectively. Then, enable private mode for both.

  3. Use the settings.xml file in your pipeline command.

    Add the -s settings.xml argument to your Maven command to specify the custom configuration file. For example: mvn test -s settings.xml.

NPM and Golang

  1. In the pipeline, configure environment variables for your username and password.

    Add the GIT_USERNAME and GIT_PASSWORD variables, and enable the private option for both.

  2. Before you run npm install or go get, add the following command:

    git config --global url."https://${GIT_USERNAME}:${GIT_PASSWORD}@codeup.aliyun.com".insteadOf "https://codeup.aliyun.com"

    For NPM, go to the NPM Build step. In the command editor, add the git config command before you run npm install. For Golang, go to the Pipeline Configuration page. In the Build stage, open the Golang Build step. In the command editor, configure the GOPROXY and GOPRIVATE environment variables, then add the git config command before the go get command.

    The GIT_USERNAME and GIT_PASSWORD are the environment variables you configured in Step 1 for your private Git repository. Replace codeup.aliyun.com with your Git repository's domain, such as github.com.