Jenkins Declarative 파이프 라인을보고 도커 컨테이너에서 내 빌드를 실행하기 시작합니다. git을 통해 npm 패키지를 가져오고 따라서 ssh 키를 설정해야하는 프로젝트가 있습니다. 내 JenkinsfileDeclarative Jenkins 파이프 라인과 Docker
pipeline {
agent {
dockerfile {
args '''--build-arg ssh_prv_key="$(cat /var/lib/jenkins-git/.ssh/id_rsa)"'''
}
}
stages {
stage('Test') {
steps {
sh 'echo $ssh_prv_key'
}
}
}
}
내에서 다음과 같은 접근 방식을 촬영 한
ARG ssh_pub_key
빌드를 실행할 때 내 Dockerfile에 다음과 같은 --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)"
등의 인수를 구축 설정할 수 있습니다를 통해 내가 온 것과
젠킨스에서 이미지를 만들 때 아래 출력을 얻습니다 (--build-arg
언급 없음).
docker build -t 085eb412f6dd28c1a7843aa9f9ed84e7c4af3e1b -f Dockerfile .
및 변수가 없습니다.
올바르게 설정하지 않았습니까? 다른 사람이 키 복사를 다른 방식으로 처리합니까?
감사
UPDATE
MY Jenkinsfile 이제 아래처럼 보이지만
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
내가 파이프 라인 선언 이외의 모든 스크립트를 실행할 수 없습니다 보인다 얻을으로 실행되지 않습니다?
def ssh_prv_key = sh script: 'cat /var/lib/jenkins-git/.ssh/id_rsa', returnStdout: true
def ssh_pub_key = sh script: 'cat /var/lib/jenkins-git/.ssh/id_rsa.pub', returnStdout: true
pipeline {
agent {
dockerfile {
args """--build-arg ssh_prv_key=\"${ssh_prv_key}\" --build-arg ssh_pub_key=\"${ssh_pub_key}\" """
}
}
stages {
stage('Test') {
steps {
sh 'echo $ssh_prv_key'
}
}
}
}
SSH 키가 이미지의 환경 변수의 일부가되도록'ENV ssh_pub_key = $ ssh_pub_key'를 추가해야합니다. 지금은 빌드 인수를 전달하지만 도움을 주신 덕분에 –