[DO-1361] add some new methods to Git and Nexus (#47)
Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech> Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/47 Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team> Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.team> Co-committed-by: Rustam Tagaev <rustam.tagaev@avroid.team>
This commit is contained in:
committed by
Denis Patrakeev
parent
e7158b0c4f
commit
4b96e40909
@@ -31,6 +31,7 @@ class Nexus implements Serializable {
|
|||||||
@param type String - type of repository
|
@param type String - type of repository
|
||||||
@return String - artifact url in Nexus
|
@return String - artifact url in Nexus
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public String upload(Map args = [:], String type = "raw") {
|
public String upload(Map args = [:], String type = "raw") {
|
||||||
String artifactName = args.artifactName ?: args.artifactPath.split('/').last()
|
String artifactName = args.artifactName ?: args.artifactPath.split('/').last()
|
||||||
String artifactUrl = args.artifactUrl ?: "${host}/repository/${args.repository}/${args.path}/${artifactName}"
|
String artifactUrl = args.artifactUrl ?: "${host}/repository/${args.repository}/${args.path}/${artifactName}"
|
||||||
@@ -138,5 +139,27 @@ class Nexus implements Serializable {
|
|||||||
|
|
||||||
Object dataJSON = script.readJSON text: res.content
|
Object dataJSON = script.readJSON text: res.content
|
||||||
return dataJSON.items[0].assets[0]
|
return dataJSON.items[0].assets[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Функция загружает артефакт в Pypi-репозиторий Nexus
|
||||||
|
@param repository String - Имя репозитория в Nexus.
|
||||||
|
@param artifact String - Путь до артефакта.
|
||||||
|
@param artifactName String - Имя артефакта которое будет отображаться в Nexus. (optional)
|
||||||
|
*/
|
||||||
|
public void uploadPypiArtifact(Map args = [:]) {
|
||||||
|
String artifactName = args.artifactName ?: args.artifact.split('/').last()
|
||||||
|
|
||||||
|
script.httpRequest(
|
||||||
|
url: "${host}/service/rest/v1/components?repository=${args.repository}",
|
||||||
|
httpMode: 'POST',
|
||||||
|
quiet: false,
|
||||||
|
formData: [[contentType: 'APPLICATION_FORM_DATA',
|
||||||
|
name: 'pypi.asset',
|
||||||
|
fileName: artifactName,
|
||||||
|
uploadFile: args.artifact]],
|
||||||
|
authentication: credentials
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class PodTemplates implements Serializable {
|
|||||||
effect: NoSchedule
|
effect: NoSchedule
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jnlp(body) {
|
public void jnlp(body) {
|
||||||
this.script.podTemplate(
|
this.script.podTemplate(
|
||||||
containers: [
|
containers: [
|
||||||
@@ -92,7 +93,6 @@ class PodTemplates implements Serializable {
|
|||||||
|
|
||||||
public void docker(body) {
|
public void docker(body) {
|
||||||
this.script.podTemplate(
|
this.script.podTemplate(
|
||||||
// serviceAccount: 'jenkins-privileged',
|
|
||||||
imagePullSecrets: this.dockerCreds,
|
imagePullSecrets: this.dockerCreds,
|
||||||
containers: [
|
containers: [
|
||||||
this.script.containerTemplate(
|
this.script.containerTemplate(
|
||||||
@@ -104,9 +104,6 @@ class PodTemplates implements Serializable {
|
|||||||
],
|
],
|
||||||
ttyEnabled: true,
|
ttyEnabled: true,
|
||||||
command: '/usr/local/bin/dockerd-entrypoint.sh',
|
command: '/usr/local/bin/dockerd-entrypoint.sh',
|
||||||
// args: """--insecure-registry=${registry} \
|
|
||||||
// --bip=192.168.222.1/24 \
|
|
||||||
// --storage-driver=overlay""",
|
|
||||||
privileged: true,
|
privileged: true,
|
||||||
resourceRequestCpu: '500m',
|
resourceRequestCpu: '500m',
|
||||||
resourceLimitCpu: '4',
|
resourceLimitCpu: '4',
|
||||||
@@ -118,7 +115,6 @@ class PodTemplates implements Serializable {
|
|||||||
instanceCap: 1,
|
instanceCap: 1,
|
||||||
showRawYaml: false,
|
showRawYaml: false,
|
||||||
volumes: [
|
volumes: [
|
||||||
// this.script.secretVolume(secretName: 'docker-config', mountPath: '/home/jenkins/.docker'),
|
|
||||||
this.script.emptyDirVolume(memory: false, mountPath: '/var/lib/docker'),
|
this.script.emptyDirVolume(memory: false, mountPath: '/var/lib/docker'),
|
||||||
this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.local'),
|
this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.local'),
|
||||||
this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.cache'),
|
this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.cache'),
|
||||||
@@ -131,4 +127,36 @@ class PodTemplates implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void git(imageVersion='v2.45.2', body) {
|
||||||
|
this.script.podTemplate(
|
||||||
|
containers: [
|
||||||
|
this.script.containerTemplate(
|
||||||
|
alwaysPullImage: true,
|
||||||
|
name: 'git',
|
||||||
|
image: "${registry}/docker-hub-proxy/alpine/git:${imageVersion}",
|
||||||
|
envVars: [
|
||||||
|
this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'),
|
||||||
|
],
|
||||||
|
ttyEnabled: true,
|
||||||
|
command: "cat",
|
||||||
|
resourceRequestCpu: '100m',
|
||||||
|
resourceLimitCpu: '100m',
|
||||||
|
resourceRequestMemory: '32Mi',
|
||||||
|
resourceLimitMemory: '32Mi',
|
||||||
|
workingDir: '/jenkins',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
instanceCap: 1,
|
||||||
|
showRawYaml: false,
|
||||||
|
volumes: [
|
||||||
|
this.script.emptyDirVolume(memory: false, mountPath: '/tmp'),
|
||||||
|
],
|
||||||
|
workspaceVolume: this.script.emptyDirWorkspaceVolume(false),
|
||||||
|
)
|
||||||
|
|
||||||
|
{
|
||||||
|
body.call()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class Git implements Serializable {
|
|||||||
* - trackingSubmodules: Boolean - Use last commit in .gitmodules, default false
|
* - trackingSubmodules: Boolean - Use last commit in .gitmodules, default false
|
||||||
* - shallow: Boolean - clone with depth = 1
|
* - shallow: Boolean - clone with depth = 1
|
||||||
* - listFiles: Boolean - List cloned files, default false
|
* - listFiles: Boolean - List cloned files, default false
|
||||||
* @return git vars: GIT_BRANCH, GIT_CHECKOUT_DIR, GIT_PREVIOUS_COMMIT, GIT_PREVIOUS_SUCCESSFUL_COMMIT, GIT_URL
|
* @return git vars: GIT_BRANCH, GIT_CHECKOUT_DIR, GIT_PREVIOUS_COMMIT,
|
||||||
|
* GIT_PREVIOUS_SUCCESSFUL_COMMIT, GIT_URL, GIT_COMMIT
|
||||||
*/
|
*/
|
||||||
public Map clone(Map args = [:]) {
|
public Map clone(Map args = [:]) {
|
||||||
Map defaultArgs = [
|
Map defaultArgs = [
|
||||||
@@ -88,7 +89,7 @@ class Git implements Serializable {
|
|||||||
* @param String gitUserMail
|
* @param String gitUserMail
|
||||||
*/
|
*/
|
||||||
public config(String gitUserName = "jenkins", String gitUserMail = "jenkins@example.com") {
|
public config(String gitUserName = "jenkins", String gitUserMail = "jenkins@example.com") {
|
||||||
script.sh """
|
script.sh """#!/bin/sh
|
||||||
git config user.name ${gitUserName}
|
git config user.name ${gitUserName}
|
||||||
git config user.email ${gitUserMail}
|
git config user.email ${gitUserMail}
|
||||||
"""
|
"""
|
||||||
@@ -187,4 +188,31 @@ class Git implements Serializable {
|
|||||||
|
|
||||||
return this.script.sh(script: "git tag $args.tagName $args.pointsAt", returnStdout: true).trim()
|
return this.script.sh(script: "git tag $args.tagName $args.pointsAt", returnStdout: true).trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get commit's author name and email
|
||||||
|
* @param commit - git hash commit
|
||||||
|
* @return Map authorInfo: Autor name and email example autor = getAutor(commit: '1234567890')
|
||||||
|
* print autor.name
|
||||||
|
* print autor.email
|
||||||
|
* @required `git` command
|
||||||
|
*/
|
||||||
|
public Map getAuthor(Map args = [:]) {
|
||||||
|
this.script.sh '''#!/bin/sh
|
||||||
|
git config --global --add safe.directory '*'
|
||||||
|
'''
|
||||||
|
Map authorInfo = [
|
||||||
|
name: this.script.sh(
|
||||||
|
script: """#!/bin/sh
|
||||||
|
git show -s --format='%an' ${args.commit}""",
|
||||||
|
returnStdout: true).trim(),
|
||||||
|
email: this.script.sh(
|
||||||
|
script: """#!/bin/sh
|
||||||
|
git show -s --format='%ae' ${args.commit}""",
|
||||||
|
returnStdout: true).trim()
|
||||||
|
]
|
||||||
|
|
||||||
|
return authorInfo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user