Skip to content

Commit

Permalink
Merge pull request CentOS-PaaS-SIG#594 from herlo/jenkins_release_job
Browse files Browse the repository at this point in the history
  • Loading branch information
paas-bot committed Jun 18, 2018
2 parents e1fec1f + 5e4032f commit 535ffd5
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 29 deletions.
89 changes: 68 additions & 21 deletions config/Dockerfiles/JenkinsfileRelease
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@ import com.cloudbees.plugins.credentials.Credentials
executionID = UUID.randomUUID().toString()
// Use repoName everywhere for dirs and repo values
repoName = 'linchpin'

DOCKER_REPO_URL = env.DOCKER_REPO_URL ?: '172.30.254.79:5000'

env.ghprbGhRepository = env.ghprbGhRepository ?: 'CentOS-PaaS-SIG/' + repoName
//env.ghprbGhRepository = env.ghprbGhRepository ?: 'herlo/' + repoName

env.ghprbActualCommit = env.ghprbActualCommit ?: 'develop'
//env.ghprbActualCommit = env.ghprbActualCommit ?: 'test_pypi_install'

env.ghprbPullAuthorLogin = env.ghprbPullAuthorLogin ?: ''

env.TARGET_BRANCH = env.TARGET_BRANCH ?: 'develop'
//env.TARGET_BRANCH = env.TARGET_BRANCH ?: 'develop-testing'
env.MASTER_BRANCH = env.MASTER_BRANCH ?: 'master'
//env.MASTER_BRANCH = env.MASTER_BRANCH ?: 'master-testing'

env.TEST_PYPI_REPO = env.TEST_PYPI_REPO ?: 'pypitest'
env.PROD_PYPI_REPO = env.PROD_PYPI_REPO ?: 'pypi'


OPENSHIFT_NAMESPACE = env.OPENSHIFT_NAMESPACE ?: 'continuous-infra'
OPENSHIFT_SERVICE_ACCOUNT = env.OPENSHIFT_SERVICE_ACCOUNT ?: 'jenkins'

env.FEDORA27_TAG = env.FEDORA27_TAG ?: 'stable'

// Pod name to use
podName = repoName + executionID
jslave_podName = 'jslave-' + repoName + '_' + executionID

library identifier: "ci-pipeline@master",
retriever: modernSCM([$class: 'GitSCMSource',
remote: "https://github.com/CentOS-Paas-SIG/ci-pipeline"])
remote: "https://github.com/CentOS-PaaS-SIG/ci-pipeline"])

library identifier: "cico-pipeline-library@master",
retriever: modernSCM([$class: 'GitSCMSource',
Expand All @@ -43,23 +54,19 @@ properties([
string(defaultValue: 'develop',
description: '',
name: 'ghprbActualCommit'),
string(defaultValue: '',
description: '',
name: 'sha1'),
string(defaultValue: '',
description: 'Git Hub Repository',
name: 'ghprbGhRepository')
]
),
])

podTemplate(name: podName,
label: podName,
podTemplate(name: jslave_podName,
label: jslave_podName,
cloud: 'openshift',
serviceAccount: OPENSHIFT_SERVICE_ACCOUNT,
idleMinutes: 0,
namespace: OPENSHIFT_NAMESPACE,

containers: [
// This adds the custom slave container to the pod.
// Must be first with name 'jnlp'
Expand All @@ -69,12 +76,19 @@ podTemplate(name: podName,
alwaysPullImage: true,
args: '${computer.jnlpmac} ${computer.name}',
command: '',
workingDir: '/workDir'),
containerTemplate(name: 'fedora27',
alwaysPullImage: true,
image: DOCKER_REPO_URL + '/' + OPENSHIFT_NAMESPACE + '/fedora27:' + FEDORA27_TAG,
ttyEnabled: false,
command: '',
privileged: true,
workingDir: '/workDir')
]
)

{
node(podName) {
node(jslave_podName) {
ansiColor('xterm') {
timestamps {
// We need to set env.HOME because the openshift slave image
Expand All @@ -95,7 +109,7 @@ podTemplate(name: podName,
pipelineUtils.verifyPod(OPENSHIFT_NAMESPACE, env.NODE_NAME)
dir(repoName) {

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'paas-bot', usernameVariable: 'GH_USER', passwordVariable: 'GH_TOKEN']]) {
withCredentials([string(credentialsId: 'paas-bot', variable: 'GH_TOKEN')]) {
checkout([$class: 'GitSCM',
branches: [[name: env.ghprbActualCommit]],
doGenerateSubmoduleConfigurations: false,
Expand All @@ -104,26 +118,27 @@ podTemplate(name: podName,
userRemoteConfigs : [
[refspec:
'+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*',
url: "https://" + GH_USER + ":" + GH_TOKEN + "@github.com/${env.ghprbGhRepository}"]
url: "https://paas-bot:" + GH_TOKEN + "@github.com/${env.ghprbGhRepository}"]
]
])
}

}
}
stage('release-version') {
stage('release-test-version') {
dir(repoName) {

sh "git checkout " + env.ghprbActualCommit
sh "git config user.name 'LinchPin Releaser'"
sh "git config user.email 'linchpin@redhat.com'"
sh "python setup.py sdist bdist_wheel"

string version = sh (
script: "python setup.py --version",
returnStdout: true
).trim()
currentBuild.displayName = "Build#: ${env.BUILD_NUMBER} - Release: " + version
if (env.ghprbActualCommit != null && env.ghprbActualCommit != "develop") {
currentBuild.description = "<a href=\"https://github.com/${env.ghprbGhRepository}/pull/${env.ghprbPullId}\">Release: (" + version + ")</a>"
}
currentBuild.displayName = "Build#: ${env.BUILD_NUMBER} - LinchPin Release: " + version

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'linchpin-releaser', usernameVariable: 'TWINE_USERNAME', passwordVariable: 'TWINE_PASSWORD']]) {
sh (
"""
Expand All @@ -144,12 +159,44 @@ username = ${TWINE_USERNAME}
password = ${TWINE_PASSWORD}
EOF

twine upload --config-file /tmp/pypirc --repository pypitest dist/*
"""
)
}
sh "git tag v" + version
sh "git push --tags origin develop"
sh "twine upload --config-file /tmp/pypirc -r " + env.TEST_PYPI_REPO + " dist/* || echo 'Version already uploaded'"
sh "git fetch origin " + TARGET_BRANCH
sh "git pull --tags origin " + TARGET_BRANCH
string tag = sh (
script: "git tag -l | grep v" + version + " || echo 'noversion'",
returnStdout: true
).trim()
if (tag != "v" + version) {
sh "git tag v" + version
sh "git push --tags origin " + env.ghprbActualCommit + ":" + TARGET_BRANCH
}
}
}
currentStage = 'test-pypi-install'
stage(currentStage) {
dir(repoName) {
pipelineUtils.executeInContainer(currentStage, "fedora27", "./config/Dockerfiles/linchpin-pip-install.sh " + version)
}
}
currentStage = "test-pypi-verify"
stage(currentStage) {
dir('linchpin') {
env.distro = "fedora27"
env.PROVIDERS = "dummy"
pipelineUtils.executeInContainer(currentStage, "fedora27", "./config/Dockerfiles/linchpin-tests.sh")
}
}
stage('release-prod-version') {
dir(repoName) {
sh "twine upload --config-file /tmp/pypirc -r " + env.PROD_PYPI_REPO + " dist/*"
}
}
stage('push-to-master') {
dir(repoName) {
sh "git push --tags origin " + env.ghprbActualCommit + ":" + MASTER_BRANCH
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions config/Dockerfiles/linchpin-pip-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash -x

# This script installs linchpin from test.pypi.org
# used by cd-linchpin-release (JenkinsfileRelease)
# will only be used on the latest distro (currently
# fedora27 and the dummy provider).

VERSION=${1}
TMPDIR=$(mktemp -d)

PYPI=https://test.pypi.org/simple

pip install -U pip setuptools

# wait for test.pypi.org to have files
sleep 10

pip download linchpin==${VERSION} --index-url ${PYPI} --retries 10 --pre --no-deps --no-binary :all: -d ${TMPDIR}

# grab the requirements.txt from the linchpin package and intall those packages from production pypi
tar -xvf ${TMPDIR}/linchpin-${VERSION}.tar.gz -C ${TMPDIR} linchpin-${VERSION}/requirements.txt --strip-components=1
pip install -r ${TMPDIR}/requirements.txt

# once deps are installed from production pypi, install linchpin from test.pypi
pip install linchpin==${VERSION} --index-url ${PYPI}

# verify linchpin is installed
linchpin --version 2>&1 | grep ${VERSION}
if [ "${?}" -eq "0" ]; then
echo SUCCESS
exit 0
fi
echo FAILURE
exit 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.17">
<actions>
<org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction plugin="workflow-multibranch@2.17">
<jobPropertyDescriptors>
<string>hudson.model.ParametersDefinitionProperty</string>
<string>com.coravy.hudson.plugins.github.GithubProjectProperty</string>
<string>jenkins.model.BuildDiscarderProperty</string>
</jobPropertyDescriptors>
</org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction>
</actions>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty plugin="openshift-sync@1.0.7">
<uid></uid>
<namespace></namespace>
<name></name>
<resourceVersion></resourceVersion>
</io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty>
<jenkins.model.BuildDiscarderProperty>
<strategy class="hudson.tasks.LogRotator">
<daysToKeep>-1</daysToKeep>
<numToKeep>20</numToKeep>
<artifactDaysToKeep>-1</artifactDaysToKeep>
<artifactNumToKeep>20</artifactNumToKeep>
</strategy>
</jenkins.model.BuildDiscarderProperty>
<com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.29.0">
<projectUrl>https://github.com/CentOS-PaaS-SIG/linchpin/</projectUrl>
<displayName></displayName>
</com.coravy.hudson.plugins.github.GithubProjectProperty>
<com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.5.3">
<gitLabConnection></gitLabConnection>
</com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
<com.sonyericsson.rebuild.RebuildSettings plugin="rebuild@1.27">
<autoRebuild>false</autoRebuild>
<rebuildDisabled>false</rebuildDisabled>
</com.sonyericsson.rebuild.RebuildSettings>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>ghprbActualCommit</name>
<description></description>
<defaultValue>develop</defaultValue>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>sha1</name>
<description></description>
<defaultValue></defaultValue>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>ghprbGhRepository</name>
<description>Git Hub Repository</description>
<defaultValue></defaultValue>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers>
<com.cloudbees.jenkins.GitHubPushTrigger plugin="github@1.29.0">
<spec></spec>
</com.cloudbees.jenkins.GitHubPushTrigger>
</triggers>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.45">
<scm class="hudson.plugins.git.GitSCM" plugin="git@3.8.0">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://github.com/CentOS-PaaS-SIG/linchpin</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>${ghprbActualCommit}</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions>
<hudson.plugins.git.extensions.impl.ChangelogToBranch>
<options>
<compareRemote>origin</compareRemote>
<compareTarget>develop</compareTarget>
</options>
</hudson.plugins.git.extensions.impl.ChangelogToBranch>
</extensions>
</scm>
<scriptPath>config/Dockerfiles/JenkinsfileRelease</scriptPath>
<lightweight>true</lightweight>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>
19 changes: 13 additions & 6 deletions config/s2i/jenkins/slave/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
FROM openshift/jenkins-slave-base-centos7:v3.7
FROM openshift/jenkins-slave-base-centos7:v3.6
##
## -------------------------------------> ^^ this is needed
## since the centosCI openshift cluster
## is running 3.6 and the slave needs the
## correct 'oc' binary to work properly
## This should be updated when the cluster
## is upgraded.
##

# Install dependencies for JenkinsfileRelease
# add ruby for ghi
RUN yum install -y epel-release
RUN yum install -y gcc python-devel libyaml-devel \
RUN yum install -y epel-release; \
yum install -y gcc python-devel libyaml-devel \
python-pip python-setuptools python-wheel python-twine \
ansible jq ruby && yum clean all && rm -rf /var/cache/yum

RUN pip install -U pip setuptools wheel twine
ansible jq ruby && yum clean all && rm -rf /var/cache/yum; \
pip install -U pip setuptools wheel twine
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource_groups:
- name: "{{ distro | default('') }}frontend"
role: os_server
flavor: m1.small
image: Fedora-Cloud-Base-26-compose-latest
image: CentOS-7-x86_64-GenericCloud-1612
count: 1
keypair: ci-factory
auto_ip: no
Expand Down
2 changes: 1 addition & 1 deletion linchpin/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__short_version__ = '1.5.5'
__version__ = '1.5.5a1'
__version__ = '1.5.5a16'

0 comments on commit 535ffd5

Please sign in to comment.