Skip to content

Added Jenkinsfile to replace fast-build-and-deploy-docs jobs #3459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
31ac3c2
Added Jenkinsfile to replace fast-build-and-deploy-docs jobs
craigcomstock Jul 10, 2025
5ad57cc
try to checkout a private repo: nova
craigcomstock Jul 10, 2025
68e3e1d
run on CONTAINERS labeled instances
craigcomstock Jul 10, 2025
6c6627b
limit to 3 builds in history
craigcomstock Jul 10, 2025
6359cab
try to refactor to use a list of repos to checkout and generate the s…
craigcomstock Jul 10, 2025
4c267ff
fixup structure
craigcomstock Jul 10, 2025
438e9e6
fix quotes to allow variable expansion?
craigcomstock Jul 10, 2025
769d6ed
do comments work? and if so, added a todo
craigcomstock Jul 10, 2025
aa2a472
added see what cloned and build stages
craigcomstock Jul 10, 2025
73fec60
get our bearings of where we are when building and running shell comm…
craigcomstock Jul 10, 2025
459a7ab
try to refactor as scripted pipeline to gain access to checkout scm f…
craigcomstock Jul 10, 2025
cdf7720
checkout documentation into a subdir
craigcomstock Jul 10, 2025
a4f9f91
try to find the right place for options
craigcomstock Jul 10, 2025
d8736b5
try to get both pipeline with buildDiscarder and node items working
craigcomstock Jul 10, 2025
3f541a7
try to use the snippet generator to set 3 builds to keep in a scripte…
craigcomstock Jul 10, 2025
83ddb84
fix syntax of buildDiscarder property
craigcomstock Jul 10, 2025
760cf2c
remove steps item as it is not needed in a scripted pipeline
craigcomstock Jul 10, 2025
d2ae595
FP4
craigcomstock Jul 10, 2025
a4d7db7
add hard-coded BRANCH env var for master
craigcomstock Jul 10, 2025
c690c17
try to clean workspaces on success
craigcomstock Jul 10, 2025
f88d2e0
add needed environment variables hard coded for now
craigcomstock Jul 10, 2025
2f3f776
add withEnv in the right location, under node and enclosing stage
craigcomstock Jul 10, 2025
b5cb7d7
move cleanWS to a stage instead of at the node level
craigcomstock Jul 10, 2025
412681e
added needed PACKAGE_UPLOAD_DIRECTORY env var with a temp value
craigcomstock Jul 10, 2025
1fa4f87
added needed env var PACKAGE_BUILD=1
craigcomstock Jul 10, 2025
6e6211c
add a working ubu22hub providing PACKAGE_UPLOAD_DIRECTORY
craigcomstock Jul 10, 2025
b8e4d25
save output as artifact
craigcomstock Jul 10, 2025
e95a3c4
refactored repo checkout to include nice data structure for multi-org…
craigcomstock Jul 10, 2025
b356336
fixup a million-ish curly braces, thanks groovy
craigcomstock Jul 10, 2025
d1184b4
cross fingers
craigcomstock Jul 10, 2025
b0e01ac
complicated, should push this checkout code to a library somehow
craigcomstock Jul 10, 2025
9ed487d
restore archiving artifacts
craigcomstock Jul 11, 2025
e622197
Explain a bit what generator/build/run.sh script does and what it pro…
craigcomstock Jul 11, 2025
45500fb
Try to add parameters as in fast-build-and-deploy-docs-master job
craigcomstock Jul 11, 2025
ffc2605
simplify clean workspace to always clean
craigcomstock Jul 11, 2025
99d293d
fixup properties
craigcomstock Jul 11, 2025
9190ad2
FP4
craigcomstock Jul 11, 2025
4f91aa7
FP4
craigcomstock Jul 11, 2025
a8f6631
FP4
craigcomstock Jul 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pipeline {
agent any

stages {
stage('Check environment'){
steps {
sh 'env'
script {
if (env.CHANGE_ID) {
echo pullRequest.title
echo pullRequest.body
}
}
}
}
}
}
116 changes: 116 additions & 0 deletions fromscratch.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
def repos = [
'cfengine': [
'core',
'enterprise',
'nova',
'masterfiles'
],
'NorthernTechHQ': [
['nt-docs': 'main'],
]
]

rev_ref_description="Use NUMBER or 'pull/NUMBER/merge' for pull request (it's merged version, THIS DOESN'T MERGE THE PR) or 'pull/NUMBER/head' to run the tests on the non-merged code. Special syntax 'tag:SOME_TAG' can be used to use a tag as a revision."

/* comments OK?
TODO:
- [ ] provide a way of specifying refs in other repos, like a coordinated multi-pr build
*/
properties([
buildDiscarder(logRotator(daysToKeepStr: '10')),
parameters([
string(name: 'CORE_REV', defaultValue: 'master'),
string(name: 'NOVA_REV', defaultValue: 'master'),
string(name: 'ENTERPRISE_REV', defaultValue: 'master'),
string(name: 'MASTERFILES_REV', defaultValue: 'master'),
string(name: 'DOCS_REV', defaultValue: 'master'),
string(name: 'DOCS_BRANCH', defaultValue: 'master', description: 'Where to upload artifacts - to http://buildcache.cloud.cfengine.com/packages/build-documentation-$DOCS_BRANCH/ and https://docs.cfengine.com/docs/$DOCS_BRANCH/'),
string(name: 'PACKAGE_JOB', defaultValue: 'testing-pr', description: 'where to take CFEngine HUB package from, a dir at http://buildcache.cloud.cfengine.com/packages/'),
string(name: 'USE_NIGHTLIES_FOR', defaultValue: 'master', description: 'branch whose nightlies to use (master, 3.18.x, etc) - will be one of http://buildcache.cloud.cfengine.com/packages/testing-pr/jenkins-$USE_NIGHTLIES_FOR-nightly-pipeline-$NUMBER/'),
string(name: 'NT_DOCS_REV', defaultValue: 'main', description: "${rev_ref_description}")
])
])

// clean workspace on Success (specify all the OTHER cases as false)

node('CONTAINERS') {
dir('documentation') {
checkout scm
}

stage('Checkout repositories') {
// Note that stages created this way are NOT available for "Restart from Stage" in jenkins UI
repos.each { org ->
println("organization is ${org.key}")
org.value.each { repo_data ->
if (!(repo_data instanceof Map)) {
repo_data=["${repo_data}": "master"]
}
repo_data.each{ repo, branch ->
stage("Checkout ${repo}") {
sh "mkdir -p ${repo}"
dir ("${repo}")
{
git branch: "${branch}",
credentialsId: 'autobuild',
url: "[email protected]:${org.key}/${repo}"
}
}
}
}
}
} // for the stage
stage('See what cloned') {
sh 'pwd'
sh 'whoami'
sh 'ls -la'
sh 'cd documentation; git log --oneline | head -n1'
}
withEnv([
'BRANCH=master',
'PACKAGE_JOB=testing-pr',
'PACKAGE_UPLOAD_DIRECTORY=jenkins-master-nightly-pipeline-152',
'PACKAGE_BUILD=1',
]) {
stage('Build') {
// hard code for now, won't actually publish yet so not too big of a deal
sh 'bash -x documentation/generator/build/run.sh'
archiveArtifacts artifacts: 'output/', fingerprint: true
}
}
stage('Publish') {
sshPublisher(publishers: [sshPublisherDesc(configName: 'buildcache.cloud.cfengine.com', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''set -x
export WRKDIR=`pwd`

mkdir -p upload
mkdir -p output

# find two tarballs
archive=`find upload -name \'cfengine-documentation-*.tar.gz\'`
tarball=`find upload -name packed-for-shipping.tar.gz`
echo "TARBALL: $tarball"
echo "ARCHIVE: $archive"

# unpack $tarball
cd `dirname $tarball`
tar zxvf packed-for-shipping.tar.gz
rm packed-for-shipping.tar.gz

# move $archive to the _site
mv $WRKDIR/$archive _site

ls -la
cd -

ls -la upload

# note: this triggers systemd job to AV-scan new files
# and move them to proper places
mv upload/* output
''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'upload/$BUILD_TAG/build-documentation-$DOCS_BRANCH/$BUILD_TAG/', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'output/')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}

stage('Clean workspace on Success') {
cleanWs()
}
}
4 changes: 4 additions & 0 deletions generator/build/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
# documentation/generator/build/run.sh
# In a container, using buildah, builds the documentation site and produces two files in output/:
# - cfengine-documentation-<branch>.tar.gz - an archive of the documentation
# - packed-for-shipping.tgz - the actual site, unpacked to _site

set -ex
trap "echo FAILURE" ERR
Expand Down