3
まず、gitにチェックインするGroovyとしてパイプラインを書いています。必要な解決策を提供しないでください。私の問題のステートメントは次のとおりです。Jenkins-pipeline groovyのプロパティファイルから変数を抽出して設定する
ファイルから変数を抽出し、グルービーオブジェクトと同じに設定します。私は無駄に他の提案を試してみた
def SERVICE_MAJOR_VERSION
node {
runGitClone(GIT_REPO_URL, GIT_HASH)
def conf = readFile("gradle.properties")
echo conf
//THE BELOW COMMENT DOESN'T WORK
//SERVICE_MAJOR_VERSION = loadEnvFromFile("SERVICE_VERSION_MAJOR", "gradle.properties", true, SERVICE_VERSION_MAJOR)
}
def runGitClone(git_repo_url, git_hash) {
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: git_hash]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'WipeWorkspace']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '85572032-4284-4095-9eec-4df70ddfdb68', url: git_repo_url]]]
}
def loadEnvFromFile(string_name, file_path, should_print_load) {
def par1 = null
def content = readFile file_path
def matcher = content =~ /${string_name}\=(.+)/
if (matcher) {
par1 = string_name + "='" + matcher[0][1] + "'"
new GroovyShell(this.binding).evaluate(par1)
if (should_print_load) {
println par1
}
}
return par1
}
を試してみた何
。特に以下の2つ。
Get values from properties file using Groovy
- 場合、ファイルから変数を抽出し、それがGroovyのオブジェクトと等しいそれは私の問題を解決する設定の作業例を持っています。