Skip to content

Commit

Permalink
Build and publish to artifactory through Jenkins
Browse files Browse the repository at this point in the history
The commit includes changes to Build.xml to use ivy to
publish the artifacts to artifactory. ivy uses ivy.xml
and ivysettings.xml to publish the artifacts.
The commit also includes Jenkinsfile which will build
the project with ant and publish the artifacts to
artifactory.
  • Loading branch information
nisanth-datastax committed Aug 13, 2024
1 parent 2821faa commit d2f4171
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 4 deletions.
94 changes: 94 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env groovy

@Library('ds-pipeline-lib')

import java.security.MessageDigest
def id = MessageDigest.getInstance("MD5").digest(System.currentTimeMillis().toString().bytes).encodeHex().toString().substring(0,8)

// Build Jython forked repository and push artifacts to artifactory

pipeline {
agent {
node {
label 'default-runner'
customWorkspace "workspace/${BUILD_NUMBER}-package-build-${id}"
}
}

tools {
jdk('jdk-8')
}

parameters {
string(name: 'buildbranch', defaultValue: 'OPSC-16690', description: 'The branch to build. Only valid for the branch build job.')
}

options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '30'))
timeout(time: 120, unit: 'MINUTES')
timestamps()
}

stages {
stage('Build') {
steps {
configFileProvider([configFile(fileId: 'gradle.properties',
replaceTokens: true,
targetLocation: 'gradle.properties')]) {
withCredentials([usernamePassword(credentialsId: 'dse-artifactory',
usernameVariable: 'ARTIFACTORY_USER',
passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
withAnt(installation: 'ant-1.10.7') {
sh "curl -O https://repo1.maven.org/maven2/org/apache/ivy/ivy/2.5.2/ivy-2.5.2.jar"
script {
if (!fileExists('/home/ubuntu/.ant/')) {
sh "mkdir /home/ubuntu/.ant/"
}
if (!fileExists('/home/ubuntu/.ant/lib')) {
sh "mkdir /home/ubuntu/.ant/lib"
}
}
sh "cp ivy-2.5.2.jar /home/ubuntu/.ant/lib/"
sh "export ARTIFACTORY_USER=$ARTIFACTORY_USER"
sh "export ARTIFACTORY_PASSWORD=$ARTIFACTORY_PASSWORD"
sh "ant publish"
// sh "ant installer"
sh "mkdir artifacts"
sh "cp dist/jython-standalone* artifacts/"
}
}
}
archiveArtifacts artifacts: 'dist/jython-standalone-*.jar', onlyIfSuccessful: true, defaultExcludes: false, caseSensitive: false
archiveArtifacts artifacts: 'dist/jython-installer.jar', onlyIfSuccessful: true, defaultExcludes: false, caseSensitive: false
}
}
stage ('Upload to artifactory') {
steps {
sh "ls artifacts/ > commandResult"

script {
env.jarfilename = readFile('commandResult').trim()
}
sh "echo $jarfilename"

withCredentials([usernamePassword(credentialsId: 'dse-artifactory',
usernameVariable: 'ARTIFACTORY_USER',
passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
// sh "curl -sSf -u '$ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD' -X PUT -T artifacts/$jarfilename 'https://repo.aws.dsinternal.org/ui/native/dse/com/datastax/opscenter/jython-standalone/2.7.3a1/$jarfilename'"
sh "curl -v --user $ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD --data-binary artifacts/$jarfilename -X PUT 'https://repo.aws.dsinternal.org/ui/native/dse/com/datastax/opscenter/jython-standalone/2.7.3a1/$jarfilename'"
// sh "curl -v --user $ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD --data-binary artifacts/$jarfilename -d 99999999 -X PUT 'https://repo.aws.dsinternal.org/artifactory/datastax-releases-local/com/datastax/opscenter/jython-standalone/2.7.3a1/$jarfilename'"
// maven(installation: 'maven_3_3_3') {
// sh "maven-publish --help"
// }
}
cleanWs notFailBuild: true
}
}
stage('wrapup') {
steps {
cleanWs notFailBuild: true
}
}
}
}
16 changes: 12 additions & 4 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Further development (c)2019 Jython Developers
Licensed to the PSF under a Contributor Agreement.
-->
<project name="jython" default="developer-build" basedir=".">
<project name="jython" default="developer-build" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">

<target name="usage" depends="common-version-strings"
description="print usage hints (-emacs removes [echo] prefix)">
Expand Down Expand Up @@ -82,6 +82,13 @@ informix.jar = ../support/jdbc-4.10.12.jar
depends="installer-preinit, jar-installer"
description="build a snapshot installer from the current state" />

<target name="publish" depends="installer" description="Publish this build into repository">
<ivy:resolve/>
<ivy:publish pubrevision="${jython.release}" status="release" resolver="jfrog-artifactory-url" forcedeliver="true" overwrite="true" >
<artifacts pattern="${dist.dir}/jython-standalone-${jython.release}.[ext]"/>
</ivy:publish>
</target>

<target name="full-build"
depends="clean, full-preinit, full-check, all-jars, jar-installer"
description="build releasable artefacts. (Use a fresh checkout for a real release)" />
Expand Down Expand Up @@ -184,7 +191,7 @@ informix.jar = ../support/jdbc-4.10.12.jar
<property name="pubs.dir" value="${basedir}/publications" />
</target>

<target name="common-jars" depends="common-dirs">
<target name="common-jars" depends="common-dirs,common-version-strings">
<!-- Names of JARs we (may) produce according to target. -->

<!-- Target: jar. Just the Jython code: needs main.classpath to work. For dev & test. -->
Expand All @@ -195,8 +202,9 @@ informix.jar = ../support/jdbc-4.10.12.jar
<property name="jython.deploy.jar" value="jython.jar" />

<!-- Target: jar-standalone. jython.standalone.jar subsumes jython.deploy.jar, and
adds the Python library as a resource. A self-contained Python in a JAR. -->
<property name="jython.standalone.jar" value="jython-standalone.jar" />
adds the Python library as a resource. A self-contained Python in a JAR.
value="jython-standalone-${jython.release}${snapshot.name}.jar -->
<property name="jython.standalone.jar" value="jython-standalone-${jython.release}.jar" />

<!-- Target: all-jars creates these and all the above JARs. -->
<property name="jython.javadoc.jar" value="javadoc.jar" />
Expand Down
9 changes: 9 additions & 0 deletions ivy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ivy-module version="2.0">
<info organisation="com/datastax/opscenter" module="jython-standalone" />
<publications>
<artifact name="jython-standalone" type="jar" ext="jar" />
</publications>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.6" />
</dependencies>
</ivy-module>
35 changes: 35 additions & 0 deletions ivysettings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<ivysettings>
<property name="jfrog-artifactory" value="SNAPSHOT" override="false"/>
<properties environment="env"/>
<property name="artifactory-user" value="${env.ARTIFACTORY_USER}"/>
<property name="artifactory-password" value="${env.ARTIFACTORY_PASSWORD}"/>

<settings defaultResolver="default"/>
<include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>

<resolvers>
<ibiblio
name="local-m2"
m2compatible="true"
root="file://${user.home}/.m2/repository"
changingPattern=".*SNAPSHOT" />

<filesystem name="local" m2compatible="true">
<artifact pattern="${user.home}/.ivy2/local/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
</filesystem>
<url name="jfrog-artifactory-url">
<ivy pattern="https://${artifactory-user}:${artifactory-password}@repo.aws.dsinternal.org/artifactory/datastax-releases-local/[organisation]/[module]/[revision]/ivy-[revision](-[classifier]).xml"/>
<artifact pattern="https://${artifactory-user}:${artifactory-password}@repo.aws.dsinternal.org/artifactory/datastax-releases-local/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
</url>

<!-- <sftp name="jfrog-artifactory-url" user="${myuser}" userPassword="${my.password}" host="https://repo.aws.dsinternal.org/artifactory/datastax-releases-local/">
<ivy pattern="[organisation]/[module]/[revision]/ivy-[revision](-[classifier]).xml"/>
<artifact pattern="[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
</sftp> -->

<chain name="default" changingPattern=".*SNAPSHOT">
<resolver ref="public"/>
<resolver ref="local-m2"/>
</chain>
</resolvers>
</ivysettings>

0 comments on commit d2f4171

Please sign in to comment.