本文章不是具體的教程. 僅僅將重點步驟記錄.
直接運行docker
docker run -d -v /root/docker/jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:lts
報錯:
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
宿主機用戶是root, /home/docker/jenkins目錄的擁有者為root用戶飞傀,而容器中jenkins user的uid為1000, 所以先將宿主機的目錄賦予權(quán)限sudo chown -R 1000:1000 /home/docker/jenkins_home
然后再執(zhí)行命令就可以了:
docker run -d -v /root/docker/jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:lts
更換源
docker中自帶的源因為眾所周知的原因訪問非常非常慢且不穩(wěn)定, 所以通過下面的腳本:
- 將原來的源更換為國內(nèi)的源.
- 將檢查網(wǎng)絡(luò)是否通暢的地址由谷歌換成百度.
$ cd {你的Jenkins工作目錄}/updates #進入更新配置位置 這里是/root/docker/jenkins_home
$ sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
登錄
從宿主機的/root/docker/jenkins_home/secrets/init***
文件里可以找到初始
配置LDAP
Note: Currently if you specify anything besides ldap for the protocol, you will receive this error. 注:目前助析,如果您指定的LDAP協(xié)議的任何內(nèi)容,除了對外冀,您將收到此錯誤。
Error: javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials] 錯誤:javax.naming.AuthenticationException:[LDAP的:錯誤代碼49 -無效證書]
Cause: The DN path or password which you have specified for the administrator is invalid. 原因:DN路徑或管理員密碼西轩,你必須指定為無效。 Any of the below will result in this error:任何下文將導(dǎo)致此錯誤:
* Pointed to non-user DN指出藕畔,非用戶的DN
* Pointed to a non-existent user, but in existing DN指出了一個不存在的用戶庄拇,但在現(xiàn)有的DN
* Pointed to non existent DN指出不存在的DN
* Pointed to an existing user, but non existing DN指出,現(xiàn)有的用戶措近,但現(xiàn)有的DN非
* Pointed to an incorrect admin DN, uid instead of cn指出,一個不正確的管理員的DN瞭郑,而不是架CN的UID
* Pointed to a non administrator user指著一個非管理員用戶
* Pointed to a valid admin but password is incorrect指出了一個有效的管理員密碼是不正確的,但
解決
將管理員用戶名和密碼設(shè)置為空.
image.png
gitlab集成jenkins
在gitlab中生成deploy token
略
在jenkins中下載gitlab的插件, 可以讓gitlab 回調(diào)jenkins的那個.
略
配置
注意點:
- 項目配置: 源碼管理 => git=> Branches to build 這里如果想匹配會隨版本號變化的分支的時候需要寫成
:origin/release-\d{8}
這樣, 注意最前面的:
- 構(gòu)建觸發(fā)器=> 回調(diào)選項, 里面可以進行高級配置以指定分支.