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
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