Skip to content

Commit

Permalink
jenkins-pipeline-examples update
Browse files Browse the repository at this point in the history
  • Loading branch information
romangurevitch committed Aug 7, 2016
1 parent 5fa140f commit 4a03668
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 31 deletions.
13 changes: 7 additions & 6 deletions jenkins-pipeline-examples/aql-example/Jenkinsfile
@@ -1,22 +1,23 @@
node {
git url: 'https://github.com/jfrogdev/project-examples.git'
def filePathPrefix = 'jenkins-pipeline-examples/aql-example/'

// Get Artifactory server instance, defined in the Artifactory Plugin administration page.
def server = Artifactory.server SERVER_ID

def buildInfo = Artifactory.newBuildInfo()
// You can set the build name and number.
// Set custom build name and number.
buildInfo.setName 'holyFrog'
buildInfo.setNumber '42'

// Read the upload spec which was downloaded from github.
def uploadSpec = readFile "${filePathPrefix}upload.json"
def uploadSpec = readFile 'jenkins-pipeline-examples/resources/recursive-flat-upload.json'
// Upload to Artifactory.
server.upload uploadSpec, buildInfo
server.upload spec: uploadSpec, buildInfo: buildInfo

// The download file contains pattern for downloading artifacts to the root directory by setting recursive=false
def downloadSpec = readFile "${filePathPrefix}download.json"
server.download downloadSpec, buildInfo
def downloadSpec = readFile 'jenkins-pipeline-examples/resources/aql-download.json'
server.download spec: downloadSpec, buildInfo: buildInfo

// Publish build info.
server.publishBuildInfo buildInfo
}
40 changes: 40 additions & 0 deletions jenkins-pipeline-examples/build-promotion-example/Jenkinsfile
@@ -0,0 +1,40 @@
node {
stage 'Build'
git url: 'https://github.com/jfrogdev/project-examples.git'

// Get Artifactory server instance, defined in the Artifactory Plugin administration page.
def server = Artifactory.server SERVER_ID

// Create the upload spec.
def uploadSpec = readFile 'jenkins-pipeline-examples/resources/props-upload.json'

// Upload to Artifactory.
def buildInfo = server.upload spec: uploadSpec

// Create the download spec.
def downloadSpec = readFile 'jenkins-pipeline-examples/resources/props-download.json'

// Download from Artifactory.
server.download spec: downloadSpec, buildInfo: buildInfo

// Publish the build to Artifactory
server.publishBuildInfo buildInfo

stage 'Promotion'
def promotionConfig = [
//Mandatory parameters
'buildName' : buildInfo.name,
'buildNumber' : buildInfo.number,
'targetRepo' : 'libs-release-local',

//Optional parameters
'comment' : 'this is the promotion comment',
'sourceRepo' : 'libs-snapshot-local',
'status' : 'Released',
'includeDependencies': true,
'copy' : true
]

// Promote build
server.promote promotionConfig
}
@@ -0,0 +1,23 @@
node {
def server = Artifactory.server SERVER_ID
def buildInfo = Artifactory.newBuildInfo()

stage 'Collect env vars'
// By default the filter is configured to exclude "*password*,*secret*,*key*"
buildInfo.env.filter.addInclude("*")
buildInfo.env.filter.addExclude("DONT_COLLECT*")

withEnv(['DO_COLLECT_FOO=BAR', 'DONT_COLLECT_FOO=BAR']) {
buildInfo.env.collect()
}

stage 'Access build info env vars'
echo buildInfo.env.vars['DO_COLLECT_FOO'] //BAR
echo buildInfo.env.vars['DONT_COLLECT_FOO'] //null

stage 'Set build retention'
buildInfo.retention maxBuilds: 1, maxDays: 2, doNotDiscardBuilds: ["3"], deleteBuildArtifacts: true

stage 'Publish buildInfo'
server.publishBuildInfo buildInfo
}
9 changes: 4 additions & 5 deletions jenkins-pipeline-examples/props-example/Jenkinsfile
@@ -1,18 +1,17 @@
node {
git url: 'https://github.com/jfrogdev/project-examples.git'
def filePathPrefix = 'jenkins-pipeline-examples/props-example/'

// Get Artifactory server instance, defined in the Artifactory Plugin administration page.
def server = Artifactory.server SERVER_ID

// Read the upload spec which was downloaded from github.
def uploadSpec = readFile "${filePathPrefix}upload.json"
def uploadSpec = readFile 'jenkins-pipeline-examples/resources/props-upload.json'
// Upload to Artifactory.
def buildInfo1 = server.upload uploadSpec
def buildInfo1 = server.upload spec: uploadSpec

// Read the upload spec and upload files to Artifactory.
def downloadSpec = readFile "${filePathPrefix}download.json"
def buildInfo2 = server.download downloadSpec
def downloadSpec = readFile 'jenkins-pipeline-examples/resources/props-download.json'
def buildInfo2 = server.download spec: downloadSpec

// Merge the upload and download build-info objects.
buildInfo1.append buildInfo2
Expand Down
13 changes: 0 additions & 13 deletions jenkins-pipeline-examples/props-example/upload.json

This file was deleted.

@@ -1,6 +1,5 @@
node {
git url: 'https://github.com/jfrogdev/project-examples.git'
def filePathPrefix = 'jenkins-pipeline-examples/props-example/'

// Get Artifactory server instance, defined in the Artifactory Plugin administration page.
def server = Artifactory.server SERVER_ID
Expand All @@ -9,19 +8,19 @@ node {
def uploadSpec = """{
"files": [
{
"pattern": "jenkins-pipeline-examples/files/ArtifactoryPipeline.zip",
"pattern": "jenkins-pipeline-examples/resources/ArtifactoryPipeline.zip",
"target": "libs-snapshot-local",
"props": "p1=v1;p2=v2"
},
{
"pattern": "jenkins-pipeline-examples/files/ArtifactoryPipelineNoProps.zip",
"pattern": "jenkins-pipeline-examples/resources/ArtifactoryPipelineNoProps.zip",
"target": "libs-snapshot-local"
}
]
}"""

// Upload to Artifactory.
def buildInfo1 = server.upload uploadSpec
def buildInfo1 = server.upload spec: uploadSpec

// Create the download spec.
def downloadSpec = """{
Expand All @@ -35,7 +34,7 @@ node {
}"""

// Download from Artifactory.
def buildInfo2 = server.download downloadSpec
def buildInfo2 = server.download spec: downloadSpec

// Merge the upload and download build-info objects.
buildInfo1.append buildInfo2
Expand Down
13 changes: 13 additions & 0 deletions jenkins-pipeline-examples/resources/props-upload.json
@@ -0,0 +1,13 @@
{
"files": [
{
"pattern": "jenkins-pipeline-examples/resources/ArtifactoryPipeline.zip",
"target": "libs-snapshot-local",
"props": "p1=v1;p2=v2"
},
{
"pattern": "jenkins-pipeline-examples/resources/ArtifactoryPipelineNoProps.zip",
"target": "libs-snapshot-local"
}
]
}
@@ -1,12 +1,12 @@
{
"files": [
{
"pattern": "files/*Artifactory*.zip",
"pattern": "jenkins-pipeline-examples/resources/*Artifactory*.zip",
"target": "libs-snapshot-local/",
"recursive": "false"
},
{
"pattern": "files/*ArtifactoryPipelineNoFlat.zip",
"pattern": "jenkins-pipeline-examples/resources/*ArtifactoryPipelineNoFlat.zip",
"target": "libs-snapshot-local",
"flat" :"false"
}
Expand Down

0 comments on commit 4a03668

Please sign in to comment.