I'm using Exec into pod and try same
as you can see ssh command obtains config and it is trying to clone repo using 443 port(not 22 as jenkins). Then I put private key in .ssh folder and clone works perfectly. That means there isn't network issue.
- Trying to clone in "Pipeline script" with git command in sh
stage('Source Code Checkout') {
steps {
container('backend') {
script{
sh "git clone [email protected]:org/repo.git"
- Trying to clone via GitSCM plugin in "Pipeline script"
stage('Source Code Checkout') {
steps {
container('backend') {
git branch: 'main',
credentialsId: 'git_user_ssh',
url: '[email protected]:org/repo.git'
Could someone please explain to me the cause of problem? Or how to specify port while cloning repo through Jenkins. Thanks in advance.
Jenkins home as was requested
container('backend') {
script{
sh "cd $JENKINS_HOME || true"
sh """cd ~
pwd
ls -la
"""
CodePudding user response:
If you use a non-standard port, specify it in the URL
git clone --help
...
ssh://[user@]host.xz[:port]/path/to/repo.git/
CodePudding user response:
I detected that next warning appears sometime
warning: JENKINS-30600: special launcher org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator$1@49c426f3; decorates RemoteLauncher[hudson.remoting.Channel@456b185:JNLP4-connect connection from 172.26.80.22/172.26.80.22:57964] will be ignored (a typical symptom is the Git executable not being run inside a designated container
So I decided to rebuild base jenkins/inbound-agent image with the following
FROM jenkins/inbound-agent:4.13-2-jdk11
ARG JENKINS_HOME=/home/jenkins
ENV JENKINS_HOME=$JENKINS_HOME
USER jenkins
RUN mkdir $JENKINS_HOME/.ssh && ssh-keyscan ssh.github.com > $JENKINS_HOME/.ssh/known_hosts
RUN echo "Host github.com\n Hostname ssh.github.com\n Port 443\n User git" > $JENKINS_HOME/.ssh/config
and.. git checkout is working for now. I don't understand how jnlp container influences on checkout inside another container based on my "mycustomimage" image.