archiveArtifacts([
allowEmptyArchive: true,
artifacts: 'output/**',
caseSensitive: true,
defaultExcludes: true,
fingerprint: false,
onlyIfSuccessful: false
])
copyArtifacts([
projectName: "Builds/Something/Name",
filter: 'target/*-somethin.jar',
selector: lastSuccessful(),
flatten: true
])
withCredentials([
usernamePassword([
credentialsId: 'CREDENTIAL_ID_USERA',
usernameVariable: 'ADMIN_USERNAME',
passwordVariable: 'ADMIN_PASSWORD'
]),
string([
credentialsId: 'CREDENTIAL_ID_API_KEY',
variable: 'ADMIN_API_KEY'
]),
sshUserPrivateKey([
credentialsId: 'CREDENTIAL_ID_KLUCZ_SSH',
keyFileVariable: 'ADMIN_SSH_KEY',
passphraseVariable: '',
usernameVariable: 'admin'
])
]) {
// ...
}
sleep([
unit: 'SECONDS',
time: sleepTime
])
waitUntil {
// ...
if (res.results != null) {
return true
} else {
sleep([
unit: 'SECONDS',
time: 10
])
return false
}
}
cleanWs()
def stages = [:] // tak się tworzy tablicę asocjacyjną
def items = ['a', 'b', 'c']
items.each {
stages[it] = { ->
stage("Stage ${it}") {
// ...
}
}
}
parallel stages
docker.build(
"nazwa:tag",
"--build-arg ARGUMENT=wartosc ."
)
def image = docker.build(
"nazwa:tag",
"--build-arg ARGUMENT=wartosc ."
)
image.push()
docker.withRegistry('adres.registry.com', credentialeDoRegistry) {
// ...
}
git([
url: '[email protected]:uzyszkodnik-lub-organizacja/i-repo.git',
branch: 'master',
credentialsId: TUTAJ_CREDENTIAL_ID,
poll: true
])
checkout([
scm: [
$class: 'GitSCM',
branches: [[ name: '*/master' ]],
userRemoteConfigs: [
[
credentialsId: TUTAJ_CREDENTIAL_ID,
url: '[email protected]:uzyszkodnik-lub-organizacja/i-repo.git'
]
]
]
])
checkout([
scm: [
$class: 'GitSCM',
branches: [[ name: '*/master' ]],
extensions: [
[
$class: 'SparseCheckoutPaths',
sparseCheckoutPaths: [
[
path: 'katalog'
]
]
]
],
userRemoteConfigs: [
[
credentialsId: TUTAJ_CREDENTIAL_IT,
url: '[email protected]:uzyszkodnik-lub-organizacja/i-repo.git'
]
]
]
])
sh('mv katalog/* .')
checkout([
$class: 'GitSCM',
branches: [[name: env.BRANCH_NAME]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[
$class: 'CloneOption',
depth: 1,
noTags: false,
reference: '',
shallow: true,
timeout: 10
],
[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false
]
],
submoduleCfg: [],
userRemoteConfigs: [
[
credentialsId: TUTAJ_CREDENTIAL_IT,
url: '[email protected]:uzyszkodnik-lub-organizacja/i-repo.git'
]
]
])
['a', 'b', 'c'].each {
print(it)
}
try {
...
} catch (err) {
// err.message
} finally {
stage('Clean up') {
cleanWs()
}
}
ansiColor('xterm') {
...
}
String txt = readFile('./sciezka/do/pliku')
writeFile([
file: 'plik.txt',
text: "Hello World\nNew Line"
])
String resp = new URL("http://example.org").getText()
withPythonEnv('/usr/bin/python3') {
...
}
def matches = (subject =~ /^(grupa)$/)
if (matches) {
String grupa = matches[0][1]
// Clean matches - important! Otherwise Jenkins will want to serialize it!
matches = null
}
timeout([
time: 5,
activity: true,
unit: 'MINUTES'
]) {
sh('npm run test')
}
build([
job: "/Path/To/Job/Without/'jobs'",
parameters: [
string(name: 'STRING_PARAM', value: 'dupa'),
booleanParam(name: 'SOME_FLAG', value: true)
],
propagate: false,
wait: false
])
currentBuild.result = 'ABORTED'
error("Wolololo")
unstable('Found Issues')
String dirName = 'katalog'
sh("mkdir ${dirName}") // pamietaj żeby stworzyć katalog najpierw
dir(dirName) {
// coś
}
withEnv(['ZMIENNA=wartosc']) {
// coś
print(env.ZMIENNA)
}
something = sh(
script: "uname -a",
returnStdout: true
)
Note: Użyj .trim()
na końcu, aby pozbyć się białych znaków.