Mulesoft Maven 部署到 RTF 401 未经授权

Mulesoft Maven Deploy To RTF 401 Unauthorized

我正在尝试使用 Maven 从 BitBucket 管道部署到 Mulesoft。部署目标是为入站流量配置的 RTF 实例。我正在使用以下 bitbucket-pipelines.yml:

image: maven:3.6.1

pipelines:
  branches:
    develop:
      - step:
          caches:
            - maven
          name: Deploy to test
          deployment: test
          script:
            - mvn clean package deploy -e -DskipMunitTests -DmuleDeploy -Dapp.name=$env.APPLICATION_NAME -Dgroup.id=$env.MULESOFT_GROUP_ID -Dapp.id=$env.MULESOFT_CONNECTED_APP_ID_DEV -Dapp.secret=$env.MULESOFT_CONNECTED_APP_DEV_SECRET -Drtf.name=$env.RUNTIME_FABRIC_NAME -Drtf.environment=$env.ANYPOINT_ENVIRONMENT -Dbusiness.group=$env.MULESOFT_BUSINESS_GROUP

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>GROUP GUID</groupId>
    <artifactId>APP NAME</artifactId>
    <version>1.0.0</version>
    <packaging>mule-application</packaging>

    <name>APP NAME</name>

    <description>APP DESCRIPTION</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <app.runtime>4.3.0</app.runtime>
        <mule.maven.plugin.version>3.4.1</mule.maven.plugin.version>
        <app.name>${env.APP_NAME}</app.name>
        <group.id>${env.GROUP_ID}</group.id>
        <app.id>${env.APP_ID}</app.id>
        <app.secret>${env.APP_SECRET}</app.secret>
        <rtf.name>${env.RTF_NAME}</rtf.name>
        <rtf.environment>${env.RTF_ENVIRONMENT}</rtf.environment>
        <business.group>${env.BUSINESS_GROUP}</business.group>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>3.4.1</version>
                <extensions>true</extensions>
                <configuration>
                    <runtimeFabricDeployment>
                        <muleVersion>${app.runtime}</muleVersion>
                        <connectedAppClientId>${app.id}</connectedAppClientId>
                        <connectedAppClientSecret>${app.secret}</connectedAppClientSecret>
                        <connectedAppGrantType>client_credentials</connectedAppGrantType>
                        <applicationName>${app.name}</applicationName>
                        <target>${rtf.name}</target>
                        <environment>${rtf.environment}</environment>
                        <businessGroup>${business.group}</businessGroup>
                        <provider>MC</provider>
                    </runtimeFabricDeployment>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-http-connector</artifactId>
            <version>1.5.19</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-sockets-connector</artifactId>
            <version>1.2.0</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-apikit-module</artifactId>
            <version>1.3.13</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    </dependencies>

    <repositories>
          <repository>
            <id>anypoint-exchange-v2</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v2/maven</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>mulesoft-releases</id>
            <name>mulesoft release repository</name>
            <layout>default</layout>
            <url>https://repository.mulesoft.org/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>mule-public</id>
            <url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
        </pluginRepository>
    </pluginRepositories>

</project>

我现在从管道收到以下错误:

[INFO] --- mule-maven-plugin:3.4.1:deploy (default-deploy) @ APP NAME ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:00 min
[INFO] Finished at: 2020-09-11T15:24:36Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mule.tools.maven:mule-maven-plugin:3.4.1:deploy (default-deploy) on project APP NAME: Execution default-deploy of goal org.mule.tools.maven:mule-maven-plugin:3.4.1:deploy failed: 401 Unauthorized: Unauthorized -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mule.tools.maven:mule-maven-plugin:3.4.1:deploy (default-deploy) on project APP NAME: Execution default-deploy of goal org.mule.tools.maven:mule-maven-plugin:3.4.1:deploy failed: 401 Unauthorized: Unauthorized
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-deploy of goal org.mule.tools.maven:mule-maven-plugin:3.4.1:deploy failed: 401 Unauthorized: Unauthorized
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.mule.tools.client.core.exception.ClientException: 401 Unauthorized: Unauthorized
    at org.mule.tools.client.core.AbstractClient.checkResponseStatus (AbstractClient.java:175)
    at org.mule.tools.client.authentication.AuthenticationServiceClient.loginWithConnectedApp (AuthenticationServiceClient.java:152)
    at org.mule.tools.client.authentication.AuthenticationServiceClient.getBearerTokenForConnectedApp (AuthenticationServiceClient.java:91)
    at org.mule.tools.client.AbstractMuleClient.getBearerToken (AbstractMuleClient.java:347)
    at org.mule.tools.client.AbstractMuleClient.init (AbstractMuleClient.java:102)
    at org.mule.tools.client.core.AbstractClient.initialize (AbstractClient.java:123)
    at org.mule.tools.client.core.AbstractClient.get (AbstractClient.java:93)
    at org.mule.tools.client.fabric.RuntimeFabricClient.getDeployments (RuntimeFabricClient.java:55)
    at org.mule.tools.verification.fabric.RuntimeFabricDeploymentVerification$RuntimeFabricDeploymentVerificationStrategy.<init> (RuntimeFabricDeploymentVerification.java:51)
    at org.mule.tools.verification.fabric.RuntimeFabricDeploymentVerification$RuntimeFabricDeploymentVerificationStrategy.<init> (RuntimeFabricDeploymentVerification.java:45)
    at org.mule.tools.verification.fabric.RuntimeFabricDeploymentVerification.<init> (RuntimeFabricDeploymentVerification.java:37)
    at org.mule.tools.deployment.fabric.RuntimeFabricArtifactDeployer.<init> (RuntimeFabricArtifactDeployer.java:50)
    at org.mule.tools.deployment.fabric.RuntimeFabricArtifactDeployer.<init> (RuntimeFabricArtifactDeployer.java:41)
    at org.mule.tools.deployment.fabric.RuntimeFabricApplicationDeployer.<init> (RuntimeFabricApplicationDeployer.java:25)
    at org.mule.tools.deployment.AbstractDeployerFactory$RuntimeFabricDeployerFactory.createArtifactDeployer (AbstractDeployerFactory.java:170)
    at org.mule.tools.deployment.DefaultDeployer.<init> (DefaultDeployer.java:36)

我已确保通过以下文档提供对连接的应用程序的权限: https://help.mulesoft.com/s/article/The-Minimum-Permission-to-Deploy-an-Application-with-Anypoint-Console-or-Maven-in-RTF

我的组织是子组织,连接的应用程序是否需要主组织的权限?我是否缺少我没有看到的权限项?我对 BitBucket Pipelines 也不是很熟悉,我需要向我的 YAML 添加任何东西吗?提前感谢您的帮助。

您似乎没有在 pom.xml mule maven 插件配置的 <runtimeFabricDeployment> 配置中提供您的 anypoint 平台用户名或密码。因此它无法进行身份验证以进行部署。

配置参考here

问题已解决。有几个问题。首先,我的 Bitbucket 管道使用以下格式注入存储库变量:$env.VAR_NAME。不需要使用 env. 前缀。那些都改成了$VAR_NAME.

接下来我的解决方案属于一个Sub-Org,全名里面有空格。我将其更改为使用 businessGroupId,并将 GUID 用于 sub-org。这些共同使 maven 部署能够正常工作。

注意:我还发现您不能在调试开关打开的情况下使用 BitBucket 管道。下载所有依赖项时超时。