瞭解如何設定項目,以便您可以使用雲管理器管理和部署項目。
現有AEM項目需要遵守一些基本規則,才能與Cloud Manager一起成功構建和部署。
pom.xml
檔案。
pom.xml
檔案可以根據需要引用盡可能多的子模組(這些子模組又可能具有其他子模組)。pom.xml
的子菜單。target
。
zip
檔案包含子目錄 target
命名 conf
和 conf.d
。在某些有限情況下,在Cloud Manager內運行時,您可能需要稍微改變構建過程,而不是在開發人員工作站上運行。 對於這些案件, 馬文配置檔案 可用於定義構建在不同環境(包括雲管理器)中的不同方式。
在Cloud Manager構建環境中激活Maven配置檔案應通過查找 CM_BUILD
環境變數 環境變數。 相反,應通過查找此變數的缺失來完成一個僅在Cloud Manager構建環境之外使用的配置檔案。
例如,如果您希望僅在在雲管理器內運行生成時才輸出一條簡單消息,則您將執行以下操作:
<profile>
<id>cmBuild</id>
<activation>
<property>
<name>env.CM_BUILD</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<echo>I'm running inside Cloud Manager!</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
要在開發人員工作站上test此配置式,您可以在命令行上啟用它(使用 -PcmBuild
)或整合開發環境(IDE)中。
如果您希望僅在生成在雲管理器之外運行時才輸出一條簡單消息,則您將執行以下操作:
<profile>
<id>notCMBuild</id>
<activation>
<property>
<name>!env.CM_BUILD</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<echo>I'm running outside Cloud Manager!</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
只有非常謹慎地使用受密碼保護的Maven儲存庫中的對象,因為通過此機制部署的代碼不會通過在Cloud Manager的質量門中實現的所有質量規則運行。 建議還部署Java源以及整個項目原始碼以及二進位代碼。
密碼保護的Maven儲存庫中的對象只應用於極少數情況和未綁定到的代AEM碼。
要使用Cloud Manager中受密碼保護的Maven儲存庫,請將密碼(以及用戶名)指定為機密 管線變數 然後在名為 .cloudmanager/maven/settings.xml
在git儲存庫中。 此檔案跟在 Maven設定檔案 架構。
當Cloud Manager生成進程啟動時, <servers>
此檔案中的元素將合併到預設 settings.xml
由雲管理器提供的檔案。 伺服器ID以 adobe
和 cloud-manager
被視為保留,不應由自定義伺服器使用。 伺服器ID與這些前置詞之一或預設ID不匹配 central
將不會被雲管理器鏡像。
如果此檔案就位,將從 <repository>
和/或 <pluginRepository>
元素 pom.xml
的子菜單。 通常,這些 <repository>
和/或 <pluginRepository>
元素將包含在 特定於雲管理器的配置檔案儘管這並非嚴格必要。
例如,假設儲存庫位於 https://repository.myco.com/maven2
,雲管理器應使用的用戶名為 cloudmanager
密碼是 secretword
。
首先,將密碼設定為管道上的密碼:
$ aio cloudmanager:set-pipeline-variables PIPELINEID --secret CUSTOM_MYCO_REPOSITORY_PASSWORD secretword
然後從 .cloudmanager/maven/settings.xml
檔案:
<?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>myco-repository</id>
<username>cloudmanager</username>
<password>${env.CUSTOM_MYCO_REPOSITORY_PASSWORD}</password>
</server>
</servers>
</settings>
最後,引用 pom.xml
檔案:
<profiles>
<profile>
<id>cmBuild</id>
<activation>
<property>
<name>env.CM_BUILD</name>
</property>
</activation>
<build>
<repositories>
<repository>
<id>myco-repository</id>
<name>MyCo Releases</name>
<url>https://repository.myco.com/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>myco-repository</id>
<name>MyCo Releases</name>
<url>https://repository.myco.com/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</build>
</profile>
</profiles>
將Java源與二進位檔案一起部署到Maven儲存庫是一個很好的做法。
配置 maven-source-plugin
在項目中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
將整個項目源與二進位檔案一起部署到Maven儲存庫是一個很好的做法。 這允許重建精確的工件。
配置 maven-assembly-plugin
在項目中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>project-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>project</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
在雲管理器中,生成可能會生成任意數量的內容包。 出於各種原因,可能希望生成內容包,但不部署它。 例如,在生成僅用於測試的內容包時或將通過生成過程中的另一個步驟重新打包的內容包(即作為另一包的子包)時,這可能很有用。
為了適應這些情況,Cloud manager將在內建內容包的屬性中 cloudManagerTarget
查找名為 的屬性。如果此屬性設定為 none
,將跳過並不部署包。 設定此屬性的機制取決於建立內容封裝的方式。例如, filevault-maven-plugin
您將按如下方式配置插件:
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<properties>
<cloudManagerTarget>none</cloudManagerTarget>
</properties>
<!-- other configuration -->
</configuration>
</plugin>
使用 content-package-maven-plugin
類似:
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<properties>
<cloudManagerTarget>none</cloudManagerTarget>
</properties>
<!-- other configuration -->
</configuration>
</plugin>
在許多情況下,同一代碼會部署到多個AEM環境。 如果可能,當Cloud Manager檢測到多個完整堆棧管道執行中使用了相同的git提交時,將避免重建代碼庫。
啟動執行時,將提取分支管道的當前HEAD提交。 提交哈希在UI中和通過API可見。 當生成步驟成功完成時,生成的對象基於該提交哈希儲存,並且可以在後續管道執行中重用。
如果包位於同一程式中,則會在管道中重複使用。 在查找可重新使用的包時,AEM會忽略分支並重複使用對象。
當重用發生時,生成和代碼質量步驟被有效地替換為原始執行的結果。 生成步驟的日誌檔案將列出最初用於生成這些對象的執行資訊。
以下是此類日誌輸出的示例。
The following build artifacts were reused from the prior execution 4 of pipeline 1 which used commit f6ac5e6943ba8bce8804086241ba28bd94909aef:
build/aem-guides-wknd.all-2021.1216.1101633.0000884042.zip (content-package)
build/aem-guides-wknd.dispatcher.cloud-2021.1216.1101633.0000884042.zip (dispatcher-configuration)
代碼質量步驟的日誌將包含類似資訊。
請考慮您的計畫有兩個開發管道:
foo
bar
兩個分支都位於同一提交ID上。
請考慮您的計畫有兩個分支:
foo
bar
兩個分支具有相同的提交ID。
foo
。bar
。在這個例子裡,那件藏物 foo
將重新用於生產管道,因為已標識同一提交哈希。
如果需要,可以通過設定管線變數來禁用特定管線的重用行為 CM_DISABLE_BUILD_REUSE
至 true
。 如果設定了此變數,則仍會提取提交哈希,並且將儲存生成的對象以供以後使用,但不會重用以前儲存的任何對象。 要瞭解此行為,請考慮以下情形。
becdddb
。 執行成功,並且會儲存結果對象。CM_DISABLE_BUILD_REUSE
變數已設定。becdddb
,由於 CM_DISABLE_BUILD_REUSE
變數。f6ac5e6
。 執行成功,並且會儲存結果對象。CM_DISABLE_BUILD_REUSE
變數已刪除。f6ac5e6
,這些工件被重用。CM_DISABLE_BUILD_REUSE
當Cloud Manager決定重新使用以前建立的生成對象時,不會考慮。Adobe工程和咨詢團隊已開發了 為開發人員提供一套全面的AEM最佳做法。