1

using the steps below in cloudbuild.yaml file, I am trying to get a java project deployed to google app-engine, each time it is committed to/tagged. It all works fine, except that the version number is auto-generated, and I would like it to be read from the the application pom.xml, where I have the following related tags.

<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/xsd/maven-4.0.0.xsd">
    <version>0.1.0-test</version>
    <groupId>com.apps</groupId>     
    <artifactId>cloudbuild-tag</artifactId>   
    <packaging>war</packaging>
    <properties>
    <appengine.maven.plugin.version>2.4.0</appengine.maven.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <appId>cloudbuild-tag</appId>
        <deploy.version>0-0-1</deploy.version>
        <appVersion>0-0-1</appVersion>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
        <repository.type>git</repository.type>
    </properties>
<dependencyManagement>
        <dependencies>
            <dependency>  
                <groupId>com.google.cloud</groupId>
                <artifactId>libraries-bom</artifactId>
                <version>16.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!-- Compile/runtime dependencies -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>             
            <version>3.1.0</version>      
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>1.9.83</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <!-- for hot reload of the web application--> 
        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
        <plugins>
            <plugin>       
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>                       
                <version>${appengine.maven.plugin.version}</version> 
                  <configuration>
                    <deploy.projectId>dev</deploy.projectId>
                    <deploy.version>0-0-1</deploy.version>
                </configuration>                   
            </plugin>                     
            <plugin>                      
                <groupId>org.apache.maven.plugins</groupId>                       
                <artifactId>maven-enforcer-plugin</artifactId>                       
                <version>3.0.0-M3</version>                        
                <executions>                             
                    <execution>                                   
                        <id>enforce-maven</id>                                   
                        <goals>                                          
                            <goal>enforce</goal>                                        
                        </goals>                                    
                        <configuration>                                         
                            <rules>                                               
                                                                  
                                <requireMavenVersion>                                                      
                                    <version>3.5.0</version>                                                    
                                </requireMavenVersion>                                             
                            </rules>                                        
                        </configuration>                                 
                    </execution>                          
                </executions>                    
            </plugin>              
        </plugins>        
    </build>  
</project>

couldbuild.yaml

  - id: 'copy local settings.xml to cloud-build/workspace'
    name: gcr.io/cloud-builders/gsutil
    args: ['cp', 'gs://bucket-test/settings.xml', 'settings.xml']
  - id: 'Stage app using mvn appengine plugin on mvn cloud build image'
    name: 'gcr.io/cloud-builders/mvn:appengine'
    args: ['--settings', '/workspace/settings.xml','install', 'appengine:stage']
  - id: 'Deploy to app engine using gcloud image'
    name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy', 'target/appengine-staging/WEB-INF/appengine-web.xml']

appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>cloudbuild-tag</application>
  <service>cloudbuild-tag</service>
  <version>0-0-1</version>
  <threadsafe>true</threadsafe>
  <sessions-enabled>false</sessions-enabled>
  <runtime>java8</runtime>

  <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
  </system-properties>

</appengine-web-app>

Appreciate any insight.... thanks very much

slk
  • 45
  • 1
  • 7
  • Can you precise the Java version that you use? And the content of the settings.xml and app.yaml file? – guillaume blaquiere Mar 05 '21 at 12:47
  • @guillaumeblaquiere, thanks. Java version is 8. settings.xml just contains path and credentials to the repo. I do not have app.yaml in the project, it is rather created after the project is staged. I do have `appengine-web.xml`, where I have defined `${appVersion}`. if this is not clear, then I will update the question. Thanks again. – slk Mar 05 '21 at 13:09
  • you have a app.yaml called in the latest step of your Cloud build. I don't undestand why you say you haven't. – guillaume blaquiere Mar 05 '21 at 13:39
  • true, that I don't have `app.yaml` in the project, and maybe that's the issue. I will try to update the `cloudbuild.yaml` so it reads from `appengine-web.xml` or will create one `app.yaml` in the project. I will report back, thanks. – slk Mar 05 '21 at 14:47
  • @guillaumeblaquiere I updated the question, reading from `appengine-web.xml` didn't help. If you would be kind enough to have a look again. Thanks. – slk Mar 05 '21 at 16:55
  • Can you share your build plugins part? – guillaume blaquiere Mar 05 '21 at 19:42
  • In fact, add the full pom.xml (only the relevant dependencies). I tested and most of the time the issue comes for there! – guillaume blaquiere Mar 05 '21 at 19:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229580/discussion-between-slk-and-guillaume-blaquiere). – slk Mar 05 '21 at 20:14
  • If you use Maven for deployment, you may consider running the command with a version parameter: mvn clean package appengine:deploy -Dapp.deploy.version=your-version-here – George Apr 21 '21 at 15:42
  • @George, I am using maven for deployment currently (so the command you mentioned is what I use currently to manually deploy from local machine to gae), but my goal is to use cloud build to deploy the app to google app engine each time it is tagged, and that the version number is picked from what is in the pom (so the commit number basically). With this, I am not sure how can I use your suggestion to improve what I currently have. – slk Apr 21 '21 at 16:34
  • It appears that currently there is there is no way to pass the content of the pom file in cloudbbuild, you may refer to [How to read pom version in cloudbuild](https://stackoverflow.com/questions/66074176/how-to-read-pom-version-in-cloudbuild). – George May 03 '21 at 16:12
  • Thanks @George,, I am hoping this will be possible soon :). – slk May 18 '21 at 14:24

0 Answers0