DO-47/Tavro_pipeline (#1)
Add first classes Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Co-committed-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
This commit is contained in:
committed by
Aleksandr Vodyanov
parent
af5323092c
commit
ecc7728355
46
build.gradle
Normal file
46
build.gradle
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
apply plugin: 'groovy'
|
||||||
|
|
||||||
|
group = 'tech.avroid'
|
||||||
|
version = '0.1.0'
|
||||||
|
description = 'Jenkins Shared Library'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url "https://repo.jenkins-ci.org/releases/"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url "https://repo.jenkins-ci.org/public/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'org.codehaus.groovy:groovy-all:3.0.2'
|
||||||
|
implementation 'com.cloudbees:groovy-cps:1.32'
|
||||||
|
implementation 'org.jenkins-ci.main:jenkins-core:2.164.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
groovy {
|
||||||
|
srcDirs = ['src', 'vars']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groovydoc {
|
||||||
|
// Set document and window titles.
|
||||||
|
docTitle = "Avroid Shared library"
|
||||||
|
windowTitle = "Avroid Shared library"
|
||||||
|
|
||||||
|
header = '''\
|
||||||
|
<img src="http://www.mrhaki.com/images/haki-logo-black-64.png"/>
|
||||||
|
<h2>Sample project</h2>
|
||||||
|
'''.stripIndent()
|
||||||
|
|
||||||
|
// Set custom footer for generated documentation.
|
||||||
|
footer = """\
|
||||||
|
<div class="custom-footer">
|
||||||
|
Generated on: ${new Date().format('yyyy-MM-dd HH:mm:ss')}
|
||||||
|
</div>""".stripIndent()
|
||||||
|
}
|
||||||
57
src/tech/avroid/scm/Git.groovy
Normal file
57
src/tech/avroid/scm/Git.groovy
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package tech.avroid.scm
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for working with Git
|
||||||
|
*/
|
||||||
|
class Git implements Serializable {
|
||||||
|
|
||||||
|
private Script script
|
||||||
|
|
||||||
|
Git(Script script) {
|
||||||
|
this.script = script
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to clone a Git repository
|
||||||
|
* @param args Map - Arguments for cloning
|
||||||
|
* - urlRepo: String - HTTP URL of the repository
|
||||||
|
* - branch: String - Branch name, default "main"
|
||||||
|
* - path: String - Directory to clone into, default "./"
|
||||||
|
* - disableSubmodules: Boolean - Disable submodules, default true
|
||||||
|
* - recursiveSubmodules: Boolean - Get submodules recursively, default true
|
||||||
|
* - parentCredentials: Boolean - Use parent repository credentials, default true
|
||||||
|
* - trackingSubmodules: Boolean - Use last commit in .gitmodules, default false
|
||||||
|
* - listFiles: Boolean - List cloned files, default false
|
||||||
|
*/
|
||||||
|
public clone(Map args = [:]) {
|
||||||
|
Map defaultArgs = [
|
||||||
|
branch: 'main',
|
||||||
|
disableSubmodules: false,
|
||||||
|
recursiveSubmodules: true,
|
||||||
|
parentCredentials: true,
|
||||||
|
trackingSubmodules: false,
|
||||||
|
path: './',
|
||||||
|
listFiles: false
|
||||||
|
]
|
||||||
|
|
||||||
|
defaultArgs.each { k, v ->
|
||||||
|
if (args[k] == null || args[k] == '' || args[k] == []) {
|
||||||
|
args[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
script.checkout([$class: 'GitSCM',
|
||||||
|
branches: [[name: "${args.branch}"]],
|
||||||
|
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${args.path}"],
|
||||||
|
[$class: 'SubmoduleOption', disableSubmodules: args.disableSubmodules,
|
||||||
|
recursiveSubmodules: args.recursiveSubmodules,
|
||||||
|
parentCredentials: args.parentCredentials,
|
||||||
|
trackingSubmodules: args.trackingSubmodules]],
|
||||||
|
userRemoteConfigs: [[url: "${args.urlRepo}"]]
|
||||||
|
])
|
||||||
|
|
||||||
|
if (args.listFiles) {
|
||||||
|
this.script.sh "ls -la ${args.path}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/tech/avroid/ssh/Ssh.groovy
Normal file
46
src/tech/avroid/ssh/Ssh.groovy
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package tech.avroid.ssh
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for work with SSH client
|
||||||
|
*/
|
||||||
|
class Ssh implements Serializable {
|
||||||
|
|
||||||
|
private Script script
|
||||||
|
private String sshKey
|
||||||
|
private String fileSshKey
|
||||||
|
|
||||||
|
Ssh(Script script, String sshKey, String fileSshKey) {
|
||||||
|
this.script = script
|
||||||
|
this.fileSshKey = fileSshKey
|
||||||
|
this.sshKey = sshKey
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add file with private Ssh key and create ssh config with disable "StrictHostKeyChecking" for all hosts
|
||||||
|
* @param sshKey String - Variable with private SSH key
|
||||||
|
* @param fileSshKey String - name of file private SSH key's in catalog ~/.ssh
|
||||||
|
*/
|
||||||
|
public void configureSshClient() {
|
||||||
|
script.println 'Configure SSH-client with private key for current user'
|
||||||
|
script.sh """
|
||||||
|
[ -d ~/.ssh ] || mkdir ~/.ssh && chmod 0700 ~/.ssh
|
||||||
|
cat $sshKey > ~/.ssh/$fileSshKey
|
||||||
|
chmod 600 ~/.ssh/$fileSshKey
|
||||||
|
echo 'Host *' > ~/.ssh/config
|
||||||
|
echo ' StrictHostKeyChecking no' >> ~/.ssh/config
|
||||||
|
echo ' UserKnownHostsFile=/dev/null' >> ~/.ssh/config
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove file with private Ssh Key and ssh config
|
||||||
|
* @param fileSshKey String - name of file private SSH key's in catalog ~/.ssh
|
||||||
|
*/
|
||||||
|
public void cleanupSshConfiguration() {
|
||||||
|
script.println 'Unconfigure SSH-client with private key for current user'
|
||||||
|
script.sh """
|
||||||
|
rm -f ~/.ssh/$fileSshKey
|
||||||
|
rm -f ~/.ssh/config
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user