Tag Archives: Jenkins

Jenkins reported an error when running the docker permission in the shell script

Errors are reported as follows

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/arduino-cli/json: dial unix /var/run/docker.sock: connect: permission denied
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Solution:

sudo gpasswd -a jenkins docker
sudo usermod -a G docker jenkins
chmod 777 /var/run/docker.sock

solve the problem

When Jenkins deploys the project, GIT reports an error fatal: index file smaller than expected

@When Jenkins deploys the project, GIT reports an error fatal: index file smaller than expectedtoc

Recently, when learning to deploy Jenkins, microservice construction has been reporting errors:

Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://gitee.com/xxx +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: fatal: index file smaller than expected

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:573)
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:994)
	... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

The GIT problem found on the Internet is solved as follows:

View links

Because Jenkins uses git deployed on the server to pull the remote warehouse, I handle it according to the above method and re push it. It still doesn’t work.

Later, it was found that the workspace in Jenkins should be cleaned up first, and Jenkins should be pulled from the remote warehouse again. The problem was solved. As shown in the figure:

Jenkins reported an error modulenotfounderror: no module named filename solution

1、 If the name of the module is the package name created by yourself, as shown in the picture:

1. Add the following code at the top of the file to be run, and the content in quotation marks is the project path:

import sys
sys.path.append(r"C:\Users\Administrator\XXXProjects\XXX")

Note: be sure to write it before all the codes introduced into the module, for example:


 

2. Add two lines of code in 1 to all imported files, such as runmethod and get in the above figure_ Data and other files need to be added

3. Another method: create a new file base.py, add the following code, and import it before the codes of all imported modules:


import sys
import os
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.abspath(os.path.dirname(curPath) + os.path.sep + ".")
sys.path.append(rootPath)

2、 If the module name is a python module, you need to reinstall it, that is, enter the command PIP install XXX in CMD

Jenkins docker push to harbor to report error

Jenkins docker push to harbor private service error solution

Jenkins reported an error

When using docker push to private service in jenkinsfile, an error is reported. The error information is as follows:

unauthorized: unauthorized to access repository: ocp/eureka-server, action: push: unauthorized to access repository: ocp/eureka-server, action: push

This is because Jenkins uses the pseudo user of Jenkins when pushing the image. Since you need to log in to push, you should first generate config.json in the current user

The current user uses docker login to generate config.json

The current user logs in with the following command

docker login ip:port

After entering the user name and you, a config.json file is generated in the. Docker directory of the current user’s root directory, as follows:

[wangxianfeng@hs ~]$ cat /root/.docker/config.json 
{
        "auths": {
                "harbor.aiuyo.com:643": {
                        "auth": "d2FuZ3hpYW5mZW5nOlhpYW5mZW5nOTk="
                }
        }
}

Copy. Docker to/var/lib/Jenkins directory

    after logging in with root, copy the/user name /. Docker/directory to/var/lib/Jenkins, and modify the folder permission chown – R Jenkins. Jenkins. Docker to/var/lib/Jenkins

     

    cp -r /root/.docker/ /var/lib/jenkins/
    cd /var/lib/jenkins/
    chown -R jenkins.jenkins .docker

    I am for this reason. After modification, it can be pushed

Jenkins series installation and deployment in docker mode

Jenkins install
1. Search for mirror

docker search jenkins

2. Pull the mirror image

docker pull jenkinsci/blueocean

3. Run

docker run -u root -d -p 8080:8080 -p 50000:50000 -v /var/jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

Browser access

http://ip:8080/

5. The initial password – this file
/var/Jenkins – data/secrets/initialAdminPassword

Jenkins git configuration error status code 128 ‘text file busy’

When Jenkins was used, all of a sudden the jobs could not be executed, and the configuration page prompted an error, as follows:

After Baidu, many solutions were only for the type “returned Status code 128”, with the detailed error of SSH-key, git server could not request to wait, and no error about “Text File busy” was found.
Finally, I found the answer to Jenkins’ official Github question,
https://github.com/joelittlejohn/embedmongo-maven-plugin/issues/28

The simple answer is that Jenkins was on a server that ran out of disk space.

Solve the problem of Too many levels of symbolic links

Too many levels of symbolic links when using ln to create soft links

root@instance-vgiv786y:/opt/jdk1.8.0_181/bin# ln-s Java /usr/local/bin/ Java

change to:
root @instancevgiv786y :/opt/jdk1.8.0_181/bin# ln-s /opt/jdk1.8.0_181/bin/ Java /usr/local/bin/ Java
Obviously I’m installing the JDK, but why would I want to create this soft connection?Just add the environment variable at /etc/profile. However, when I connected this server as one of Jenkins’ nodes, I was surprised to find that Java could not be found. Obviously, I added the environment variable and it took effect. Jenkins had to look under various bin directory, so I created this soft connection.

Jenkins SVN error Server SSL certificate verification failed: issuer is not trusted

Jenkins was used for continuous integration in the project. SVN command was found in the BAT file and BAT Times: Server SSL Certificate Verification Failed: Bach is not trusted was executed
The server SSL certificate has failed to authenticate and the issuer is not trusted
The solution,
Add: –non-interactive — trust-server-CERT after the SVN command. Can solve
Refer to SVN for the meaning of the command.

ERROR: Failed to parse POMs (How to Fix)

recently had this problem while working on the Jenkins build release,

ERROR: Failed to parse POMs
java.io.IOException: Can't read POM: /opt/gamma/.jenkins/jobs/indra-parent/workspace/pom.xml
	at jenkins.plugins.maveninfo.extractor.properties.PomPropertiesFinder.findProperties(PomPropertiesFinder.java:54)
	at jenkins.plugins.maveninfo.extractor.MavenInfoExtractor.extract(MavenInfoExtractor.java:58)
	at jenkins.plugins.maveninfo.extractor.MavenInfoEnvironment.tearDown(MavenInfoEnvironment.java:42)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:882)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
	at hudson.model.Run.execute(Run.java:1720)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)

maven has actually been built and turned out to be a pom.xml header

The error was caused by a corrupt XML header which contained merge conflicts.

head is normal after modification for the following

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	


Python + Requests +Excel+Jenkins interface automation

python+requests+Excel+Jenkins interface automation

summary most people do interface automation process, found that basically is: python + requests do interface requests; Excel is used to store use cases; HTMLTestRunner generates test reports; Jenkins completes scheduled tasks.

actually takes only a fraction of the time to complete this process, with most of the time wasted in setting up the environment and writing use cases. Here I’m going to write down some of the problems.

interface request
(1) configuration request method: get and post method simple packaging, header parameter setting

# _*_coding:utf-8 _*
import requests

#get请求
def get(url,querystring):
    headers = requestHeader()
    response = requests.request("GET", url, headers=headers, params=querystring)
    # print response.url
    return response

#post请求
def post(url,payload,querystring):
    headers = requestHeader()
    response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
    # print response.url
    return response

#设置请求的header
def requestHeader():
    headers = {
    'Content-Type': "application/json",
    'Cache-Control': "no-cache"
    }
    return headers

(2) for the body of a post request, we used a “dict” in text at the beginning, but it always returned “error”. After that, postman used to debug and directly copied the body reference that had been converted into json to make the request, and it worked.

WechatIMG12.jpeg

can be used to convert some problematic bodies in this way.

Another way to convert

(3) body to json: through ast module for conversion (recommended)

import ast
caseParams      =   ast.literal_eval(caseParams)

(4) get use case Excel

through openpyxl module

#用例名
caseName    =   caseFile.getCellVaule(ws,rowIndex,1)
#url
caseUrl     =   caseFile.getCellVaule(ws,rowIndex,3)
#请求方式
caseMethod  =   caseFile.getCellVaule(ws,rowIndex,4)
#参数
caseParams  =   caseFile.getCellVaule(ws,rowIndex,5)

note: in the process of obtaining the use case information, some parameters need to be fault-tolerant
A: whether there are parameters, if there are no parameters, need to pass null;
B: get parameter and post body need to be handled separately:
get parameter is ‘& Param ‘in the form of clear text spliced in the URL;

#将请求参数转换为json格式
caseParams  =   ast.literal_eval(caseParams)
keys        =   dict(caseParams).keys()
values      =   dict(caseParams).values()
for x in xrange(0,len(keys)):
  tempQuery[keys[x]] = values[x]

, the body of the post needs to be put in dict;

caseParams      =   ast.literal_eval(caseParams)

(5) split the required parameters and write the result to the file

#请求返回的内容,转换为json格式
text            =   json.loads(response.text)
                caseFile.setCellValue(ws,rowIndex,6,response.text)

#URL请求耗时
spendTime       =   response.elapsed.total_seconds()
                caseFile.setCellValue(ws,rowIndex,7,spendTime)

#请求结果状态
statue          =   response.status_code
                caseFile.setCellValue(ws,rowIndex,8,statue)
self.assertEqual(statue, 200)

(6) writes the result of the request to an HTML file and displays

WechatIMG13.jpeg

(7) is configured to Jenkins to periodically execute the accessibility of the view interface

learning Python address: https://ke.qq.com/course/2707042?flowToken=1025648

if there are any problems you for learning Python, learning methods, learning course, how to learn efficiently, can be consulting me at any time, or the lack of system study materials, I do this year longer, they think is experienced, can help everyone puts forward constructive Suggestions, this is my Python communication qun: 785128166, if you have any question can be consulting me at any time.