1+ /*
2+ Copyright (c) 2021 LinkedIn Corp.
3+ Licensed under the Apache License, Version 2.0 (the "License");
4+ you may not use this file except in compliance with the License.
5+ You may obtain a copy of the License at
6+ http://www.apache.org/licenses/LICENSE-2.0
7+ Unless required by applicable law or agreed to in writing, software
8+ distributed under the License is distributed on an "AS IS" BASIS,
9+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+ See the License for the specific language governing permissions and
11+ limitations under the License.
12+ */
13+
14+ /**
15+ * The purpose of this script is to configure the following tasks for a sub-project:
16+ * - artifactoryPublish: publishes all artifacts for the "release" publication to JFrog; depends on...
17+ * - generatePomFileForReleasePublication: defined in publications.gradle
18+ * - assertArtifactsExist: defined in publications.gradle
19+ * - assertJFrogCredentialsExist: asserts that JFrog credentials are present as environment variables
20+ */
21+ apply plugin : ' com.jfrog.artifactory' // https://www.jfrog.com/confluence/display/rtf/gradle+artifactory+plugin
22+
23+ final String jfrogUserEnv = ' JFROG_USER'
24+ final String jfrogKeyEnv = ' JFROG_KEY'
25+
26+ def jfrogUser = System . getenv(jfrogUserEnv)
27+ def jfrogKey = System . getenv(jfrogKeyEnv)
28+
29+ // Configure the "artifactoryPublish" task for the "release" publication.
30+ artifactory {
31+ contextUrl = ' https://linkedin.jfrog.io/artifactory'
32+ clientConfig. setIncludeEnvVars(false )
33+
34+ publish {
35+ repository {
36+ repoKey = ' parseq' // The Artifactory repository key to publish to
37+ username = jfrogUser // The publisher user name
38+ password = jfrogKey // The publisher password
39+ }
40+
41+ defaults {
42+ publications(publishing. publications. release)
43+ }
44+ }
45+ }
46+
47+ // Utility task to ensure that we aren't attempting a publish without providing JFrog credentials.
48+ task assertJFrogCredentialsExist () {
49+ doLast {
50+ if (! jfrogUser || ! jfrogKey) {
51+ throw new GradleException (
52+ " Cannot perform JFrog upload. Missing '${ jfrogUserEnv} ' or '${ jfrogKeyEnv} ' environment variable. " +
53+ " These are set in the .travis.yml config file (if running in CI) or on the CLI (if running locally)." )
54+ }
55+ }
56+ }
57+
58+ // Gather all assertion/publication/publish tasks into one task
59+ artifactoryPublish. dependsOn " assertArtifactsExist" , assertJFrogCredentialsExist, " generatePomFileForReleasePublication"
0 commit comments