이것은 내가 생각한 (시시한) 해결책입니다.
필자는 작업에 사용한 레이블의 채널을 얻기 위해 자신에게 Util 클래스를 작성했습니다.
import jenkins.model.Jenkins
import hudson.FilePath
import hudson.remoting.Channel
/**
* returns the channel of the given label, might be null
*
* realy bad solution why: when multiple JenkinsSlaves have the same label, this will probably not work anymore,
* because the channel of the first node is returned
* For empty labels it does not work either
* @param jenkins the jenkins instance
* @param label the associated label for the running node, not empty, not null
* @return a channel of a Node associated with given label, might be null
*/
@com.cloudbees.groovy.cps.NonCPS
public static Channel getChannel(Jenkins jenkins, String label) {
assert jenkins !=null : 'JenkinsUtil.getChannel() does not work for null Jenkins'
assert label!=null : 'JenkinsUtil.getChannel() does not work for null Labels'
assert !label.isEmpty() : 'JenkinsUtil.getChannel() does not work for empty Labels'
Set<Node> nodes = jenkins.getLabel(label).getNodes()
assert nodes.size() < 2 : 'JenkinsUtil.getChannel() might not work correctly for Label which are associated with multiple nodes. Fix Me!'
assert nodes.size() > 0 : "JenkinsUtil.getChannel(): No node found for Label ${label}"
return nodes[0].getChannel()
}
이 채널을 통해 이제 원격 컴퓨터에서 파일을 만들 수 있습니다.
FilePath remoteWorkspace = new FilePath(JenkinsUtil.getChannel(Jenkins.instance,LABEL_STRING), env.WORKSPACE)
FilePath webserverConfiguration = new FilePath(remoteWorkspace, 'webserver.conf')
webserverConfiguration.write('someText', null)
왜 이렇게 했습니까? 'build'변수는 WorkkflowScript에서 사용할 수 없었습니다.
왜 '젠킨스 파일'에서 이것을하고 싶습니까? 전반적으로 달성하려는 것은 무엇입니까? 왜 기존의'node' 단계와'sh' 기능을 사용할 수 없습니까? 나에게이 질문은 [XY 문제] (https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)처럼 들린다. – mkobit
내가 실제로 달성하고자하는 것은 Jenkins 클라이언트에서 사용자 정의 된 (Apache) 웹 서버를 시작하는 것입니다. 이를 위해 웹 서버를 시작하기 전에 https.conf 파일을 변경해야합니다. shov/bat 명령보다 Groovy 클래스를 사용하는 것이 더 편합니다. 왜냐하면 Groovy에 익숙하기 때문에 Groovy 클래스를 테스트 한 다음 실제로 sh/bat 명령을 테스트하는 것이 좋습니다. – genmad