https://github.com/hellojukay/jenkins-experience
some experience about jenkins
https://github.com/hellojukay/jenkins-experience
Last synced: about 1 year ago
JSON representation
some experience about jenkins
- Host: GitHub
- URL: https://github.com/hellojukay/jenkins-experience
- Owner: hellojukay
- Created: 2019-05-30T01:51:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-30T06:24:51.000Z (about 7 years ago)
- Last Synced: 2025-01-29T08:34:06.595Z (over 1 year ago)
- Language: Groovy
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jenkins-experience
some experience about jenkins
## problems
### git clone to special dir
```groovy
checkout scm: [$class: 'GitSCM',extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'deploy-smac']], userRemoteConfigs: [[url: "${REPO}", credentialsId: "${credential}"]], branches: [[name: "${VERSION}"]]],poll: false
```
### read ini config
```groovy
def call(String file) {
def m = [:]
def lines = new File(file).readLines()
for(line in lines) {
def kv = line.split("=")
if(kv.length == 2) {
def k = kv[0]
def v = kv[1]
m[k] = v
}
}
return m
}
```
### list git remote tags
```groovy
def call(String git_url, String credentialsId = "gitlab") {
def GIT_USER = ""
def GIT_PW = ""
withCredentials([usernamePassword(credentialsId: "${credentialsId}", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
def u = URLEncoder.encode(GIT_USERNAME,'UTF-8')
def p = URLEncoder.encode(GIT_PASSWORD,'UTF-8')
GIT_USER = u
GIT_PW = p
}
git_url = git_url.replace("//","//${GIT_USER}:${GIT_PW}@")
def gettags = ("git ls-remote -t -h ${git_url}").execute()
return gettags.text.readLines().collect {
it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}
}
```