基于GCB的JavaFX项目非Docker CI配置需求(JDK8u201)
Got it, let's walk through setting up your Cloud Build CI for that multi-module repo step by step. I’ll break down everything you need to configure in cloudbuild.yaml and associated GCP triggers to meet all your requirements:
Configure Cloud Build CI for Multi-Module Repo (Develop Branch PRs)
1. First: Set Up the PR Trigger (GCP Console)
Before touching the YAML, configure a Cloud Build trigger to run only on pull requests targeting the develop branch:
- Navigate to the Cloud Build Triggers page in your GCP project
- Create a new trigger linked to your GitHub repo
- Set the trigger event to "Pull request"
- Under "Target branch", enter
^develop$to restrict it to PRs merging into develop - Ensure the trigger uses the
cloudbuild.yamlfrom the PR's source branch
2. Full cloudbuild.yaml Configuration
Here's a ready-to-use config that handles JDK8u201 installation, JavaFX project builds, and artifact storage:
steps: # Step 1: Install Oracle JDK 8u201 (handles license agreement) - name: 'ubuntu:20.04' id: 'setup-jdk8u201' args: ['bash', '-c', | apt-get update && apt-get install -y wget unzip # Accept Oracle's license via cookie header (required for legal download) wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz tar -xzf jdk-8u201-linux-x64.tar.gz -C /usr/local/ update-alternatives --install /usr/bin/java java /usr/local/jdk1.8.0_201/bin/java 1 update-alternatives --install /usr/bin/javac javac /usr/local/jdk1.8.0_201/bin/javac 1 # Verify installation java -version ] # Step 2: Install build tool (Gradle here; swap for Maven if needed) - name: 'ubuntu:20.04' id: 'setup-build-tool' args: ['bash', '-c', | apt-get install -y gradle gradle --version ] waitFor: ['setup-jdk8u201'] # Step 3: Build the JavaFX project (adjust commands to match your project's setup) - name: 'ubuntu:20.04' id: 'build-javafx' args: ['bash', '-c', | cd JavaFX_project # Use ./gradlew instead if your project has a Gradle wrapper gradle clean build javapackager # javapackager creates native executables for JDK8 ] waitFor: ['setup-build-tool'] env: - 'JAVA_HOME=/usr/local/jdk1.8.0_201' # Step 4: Upload artifacts to Cloud Storage for easy download - name: 'gcr.io/cloud-builders/gsutil' id: 'upload-artifacts' args: ['cp', '-r', 'JavaFX_project/build/distributions/*', 'gs://YOUR_BUCKET_NAME/javafx-builds/${BUILD_ID}/'] waitFor: ['build-javafx'] # Define artifacts to persist post-build artifacts: objects: location: 'gs://YOUR_BUCKET_NAME/javafx-builds/${BUILD_ID}/' paths: - 'JavaFX_project/build/distributions/**' # Optional: Skip builds if only legacy/Arduino code changes (save time!) options: substitution_option: 'ALLOW_LOOSE'
Key Details to Adjust:
- JDK License: Make sure you comply with Oracle's license terms for using JDK8u201 in your CI pipeline.
- Build Tool Swap: If your JavaFX project uses Maven instead of Gradle, replace the Gradle steps with
apt-get install -y mavenand runmvn clean package javafx:package(adjust based on your Maven plugin setup). - Cloud Storage Bucket: Replace
YOUR_BUCKET_NAMEwith your existing GCP Cloud Storage bucket name (create one first if you don't have it). - Artifact Path: Update the paths in the build and upload steps to match where your JavaFX project outputs executables (e.g.,
build/jpackageif using a newer plugin, orbuild/libsfor JARs).
3. Making Artifacts Accessible
- Direct Download Links: After each successful build, artifacts are stored in your Cloud Storage bucket. You can set up a Cloud Build notification to automatically post the bucket URL in the PR comment, so reviewers can download the executable directly.
- Repo Storage Note: Storing build artifacts directly in the repo isn't recommended (it bloats the repo over time), but if you must, you can add an extra step to commit and push artifacts to a dedicated
artifactsbranch—though Cloud Storage is the cleaner, scalable option.
4. Test the Setup
Create a test PR to develop and verify:
- The Cloud Build trigger fires automatically
- The build logs confirm JDK8u201 is being used
- Artifacts appear in your Cloud Storage bucket
内容的提问来源于stack exchange,提问作者bankairyuu
相关产品推荐
相关产品推荐

