使用Jenkins Artifactory插件和Gradle,我能够成功部署到我的Artifactory实例。但是,我无法使用输入到Jenkins配置中的凭据来解析来自同一存储库的工件。
这是build.gradle
,正好来自Artifactory的Artifactory的“生成构建脚本”功能。
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
buildscript {
repositories {
maven {
url 'http://artifactory.myorg.com:8081/artifactory/plugins-release'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
//Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3"
}
}
allprojects {
apply plugin: "com.jfrog.artifactory"
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'libs-release'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
dependencies {
compile group: "com.myorg", name: "internal-library", version: '1.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Jenkins的工作配置:
Jenkins Artifactory插件配置:
错误:
FAILURE: Build failed with an exception.
* Where:
Build file '/var/lib/jenkins/jobs/deleteme/workspace/build.gradle' line: 10
* What went wrong:
A problem occurred evaluating root project 'untitled2'.
> Could not find property 'artifactory_user' on Credentials [username: null].
在本地,解析工件(artifactory_user
等)已解决,因为我在本地~/.gradle/gradle.properties
中配置了它们。但是,构建失败,因为未定义artifactory_user
。当然,我可以配置一个gradle.properties
供Jenkins使用(这样可行),但这个假设的是如何工作的?似乎Jenkins Artifactory Plugin Gradle集成应该以某种方式传达解析器凭据。有没有办法在Jenkins的两个地方复制凭证?
答案 0 :(得分:2)
tl; dr username = "${project.getProperty('artifactory.publish.username')}"
注意:我还没有在Jenkins机器上测试过这个
Jenkins artifactory插件的gradle集成似乎做了两件事
两者都涉及将文件写入临时文件夹(即Linux上的/tmp
)。如果您有权访问构建服务器,那么临时文件夹中可能会包含大量buildInfo\d{19}.properties
和init-artifactory\d{19}gradle
个文件。
查看其中一个buildInfo文件会显示解析和发布凭据分别存储在artifactory.resolve.username
和artifactory.publish.username
中。
尝试设置并尝试直接使用${artifactory.publish.username}
在我的本地计算机上不起作用;我假设它与gradle在设置之前尝试访问属性有关。但project.getProperty
方法有效。
buildscript {
repositories {
maven {
url 'http://artifactory.myorg.com:8081/artifactory/plugins-release'
credentials {
username = "${project.getProperty('artifactory.resolve.username')}"
password = "${project.getProperty('artifactory.resolve.password')}"
}
}
}
}
artifactory {
publish {
contextUrl = "${project.getProperty('artifactory.publish.contextUrl')}"
repository {
repoKey = 'libs-release-local'
username = "${project.getProperty('artifactory.publish.username')}"
password = "${project.getProperty('artifactory.publish.password')}"
maven = true
}
}
resolve {
repository {
contextUrl = "${project.getProperty('artifactory.resolve.contextUrl')}"
repoKey = 'libs-release'
username = "${project.getProperty('artifactory.resolve.username')}"
password = "${project.getProperty('artifactory.resolve.password')}"
maven = true
}
}
}
您必须相应地更新本地~/.gradle/gradle.properties
artifactory.publish.contextUrl=<artifactory-url>
artifactory.publish.username=<username>
artifactory.publish.password=<password>
artifactory.resolve.contextUrl=<artifactory-url>
artifactory.resolve.username=<username>
artifactory.resolve.password=<password>
答案 1 :(得分:0)
我也正在用这个敲我的头...我自己尝试了所有的组合,唯一一个似乎正在工作的是将gradle.properties添加到jenkins服务器。
最后我最终没有使用jenkins alltogether中的artifactory gradle插件.R将它添加到build.gradle中,只需从Jenkins Server gradle插件中调用artifactoryPublish。