Answer the question
In order to leave comments, you need to log in
How to correctly write a file in the attached class method to the main Jenkinsfile?
I have a groovy class in which in the method I am trying to write a file
print("Loaded class MyClass.groovy")
public class Prepare {
private List service1 = ["dev-app-0001","dev-app-0002","dev-app-0003"];
private List service2 = ["dev-app-0004","dev-app-0005","dev-app-0006","dev-app-0007"]
String GetHosts() {
List result = this.service1+this.service2
return ("[allsystems]\n"+result.join('\n')+"\n").toString();
}
}
String PrepareHosts() {
Prepare pr = new Prepare();
// pr.setPath(Path)
pr.GetHosts();
Object hosts = new File("/data/jenkins/workspace/example1/update_sshkeys/hosts");
// hosts.createNewFile();
hosts.write(pr.GetHosts())
return pr.GetHosts();
}
return this
stage('Git clone') {
checkout scm
script {
def hosts = load "MyClass.groovy"
print "Result " + hosts.PrepareHosts();
writeFile file: "hosts", text: hosts.PrepareHosts()
}
}
writeFile file: "hosts", text: hosts.PrepareHosts()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question