“Using Jenkins agents with docker”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
第53行: 第53行:
 
     $ VARS="${VARS1}|${VARS2}"                                                       
 
     $ VARS="${VARS1}|${VARS2}"                                                       
 
     $ docker exec agent1 sh -c "env | egrep -v '^(${VARS})' >> /etc/environment"      </pre>
 
     $ docker exec agent1 sh -c "env | egrep -v '^(${VARS})' >> /etc/environment"      </pre>
 +
 +
=trouble shooting=
 +
<pre>
 +
java.io.IOException: Java not found on hudson.slaves.SlaveComputer@d48b725. Install Java 8 or Java 11 on the Agent.
 +
alpine 安装java
 +
 +
apk add openjdk8
 +
 +
java目录
 +
 +
/opt/java/openjdk/bin/java
 +
 +
要安装这个插件
 +
SSH Agent
 +
 +
SSH build Agents
 +
 +
这两个搞得有点久
 +
 +
/home/jenkins  工作目录改成这个 /tmp好了 ? 不是的
 +
 +
 +
Node and Label parameter    nodelabelparameter
 +
Job Restrictions  插件  不然
 +
I can't find “Restrict where this project can be run” in the configure page
 +
 +
 +
就是手工添加的了 有如当年在xk 选择git 版本一样
 +
参数化构建过程  -->添加参数 ->Node -->
 +
 +
 +
https://plugins.jenkins.io/nodelabelparameter/
 +
 +
docker pull jenkins/ssh-slave
 +
 +
</pre>

2021年8月5日 (四) 11:52的版本

** Generating an SSH key pair

    ssh-keygen    -t dsa -f ~/.ssh/jenkins_agent_key                                 

*** Create a Jenkins SSH credential

                                                                                     
         Go to your Jenkins dashboard;                                                
                                                                                      
         Go to Manage Jenkins option in main menu and click on credentials button;    
         select the drop option Add Credentials from the global item;                 
                                                                                      
     Fill the form:                                                                   
                                                                                      
         Kind: SSH Username with private key;                                         
                                                                                      
         id: jenkins                                                                  
                                                                                      
         description: The jenkins ssh key                                             
                                                                                      
         username: jenkins                                                            
                                                                                      
         Private Key: select Enter directly and press the Add button to insert your   
         private key from ~/.ssh/jenkins_agent_key                                    
                                                                                      
         Passphrase: fill your passphrase used to generate the SSH key pair and then  
         press OK   


==**  Creating your Docker agent    ==                                                  
    run the command to start your first agent:                                       
                                                                                      
     docker run -d --rm --name=agent1 -p 22:22 \                                      
     -e "JENKINS_AGENT_SSH_PUBKEY=[your-public-key]" \                                
     jenkins/ssh-agent:alpine                                                         
                                                                                      
                                                                                      
                                                                                      
     实际替换上你的pub key                                                            
     docker run -d --rm --name=agent1 -p 222:22 \                                     
     -e "JENKINS_AGENT_SSH_PUBKEY=ssh-rsa                                             
     AAAAB3NzaC1yc2EAAAADAQABAAABAQCljcroCTtT+Qipw8NvncMZx731Dv4fjZPt09JaD+aR3jdNWp5e\
     bpKJQGD12UzN6/2lRPHipIroY/WKt+MIy9y+0iQ1Om+nl01j6GHkVeGVhoKCmv4dRQgvoczYHO5ccXNo\
     uVeTnopg+4UiKWzimOVE0pcu06H//OFEGR24BT8bBAHrV17EYshhY09I9LXzw8O+oSsn217frmNNEfUo\
     aq72verbEUrPS/NfBwdb4W4Pfdc874bUcnt7UEFa9VSSeLFa0Xp7xzNurZye+m9WAn/WhjDXQJgZE3Ql\
     yYLc6ZT9k4EdXlJgF/GeZ4wX4p9itnmimMiYy+eieb4jwHlAWryh root@gitlabzbx              
     " \                                                                              
     jenkins/ssh-agent:alpine                                                         
                                                                                      
     Now run the following command to update the container environment:               
                                                                                      
     $ VARS1="HOME=|USER=|MAIL=|LC_ALL=|LS_COLORS=|LANG="                             
     $ VARS2="HOSTNAME=|PWD=|TERM=|SHLVL=|LANGUAGE=|_="                               
     $ VARS="${VARS1}|${VARS2}"                                                       
     $ docker exec agent1 sh -c "env | egrep -v '^(${VARS})' >> /etc/environment"      

trouble shooting

java.io.IOException: Java not found on hudson.slaves.SlaveComputer@d48b725. Install Java 8 or Java 11 on the Agent.
alpine 安装java 

apk add openjdk8

java目录 

/opt/java/openjdk/bin/java

要安装这个插件 
SSH Agent 

SSH build Agents

这两个搞得有点久 

/home/jenkins  工作目录改成这个 /tmp好了 ? 不是的 


Node and Label parameter    nodelabelparameter
Job Restrictions  插件  不然 
I can't find “Restrict where this project can be run” in the configure page


就是手工添加的了 有如当年在xk 选择git 版本一样
参数化构建过程  -->添加参数 ->Node -->


https://plugins.jenkins.io/nodelabelparameter/

docker pull jenkins/ssh-slave