Reputation: 37126
I am trying to use multiple CodeCommit sources in my CodePipeline build. I defined a secondary source pointing to a project in CodeCommit in CodeBuild and assigned it "sec_proj" identifier. In my main project I have a Gradle build which has the following code
copy {
from System.getProperty("CODEBUILD_SRC_DIR_sec_proj", CODEBUILD_SRC_DIR_sec_proj)
into "$buildDir/sec_proj"
}
When I define CODEBUILD_SRC_DIR_sec_proj
in my local environment everything runs as expected, files from the 2nd project are copied and build completes. However when I attempt to run it in my pipeline I get the following error:
17:50:26.092 [ERROR]
[org.gradle.internal.buildevents.BuildExceptionReporter] Caused by:
groovy.lang.MissingPropertyException: Could not get unknown property
'CODEBUILD_SRC_DIR_sec_proj' for object of type
org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated.
So obviously my gradle process does not have this variable available.
I tried to force it using the following syntax in my buildspec.yml
phases:
build:
commands:
- ./gradlew -i -d -S build -DCODEBUILD_SRC_DIR_sec_proj=$CODEBUILD_SRC_DIR_sec_proj
And it failed with same message. And since according to the documentation
Your primary source is defined under the source attribute. All other sources are called secondary sources and appear under secondarySources. All secondary sources are installed in their own directory. This directory is stored in the built-in environment variable CODEBUILD_SRC_DIR_sourceIdentifer.
it looks like I'm missing something?
Upvotes: 0
Views: 722
Reputation: 1488
Looking at your code:
System.getProperty("CODEBUILD_SRC_DIR_sec_proj", CODEBUILD_SRC_DIR_sec_proj)
and the signature of the method:
System.getProperty(String key, String defaultValue)
I think the error message is actually returning to the variable CODEBUILD_SRC_DIR_sec_proj
which might not be defined. (Maybe you've defined it elsewhere, I'm not sure)
I would recommend simply:
copy {
from System.getProperty("CODEBUILD_SRC_DIR_sec_proj")
into "$buildDir/sec_proj"
}
Upvotes: 0
Reputation: 37126
Here's the solution. Turns out CODEBUILD_SRC_DIR_sec_proj
is there but System.getProperty("CODEBUILD_SRC_DIR_sec_proj", CODEBUILD_SRC_DIR_sec_proj)
will not get it. But System.getProperties().getProperty("CODEBUILD_SRC_DIR_sec_proj")
will. Then it works like a charm
Upvotes: 2