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 62 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
512a800
Added Jenkinsfile to replace fast-build-and-deploy-docs jobs
craigcomstock Jul 10, 2025
a08f995
try to checkout a private repo: nova
craigcomstock Jul 10, 2025
ccae110
run on CONTAINERS labeled instances
craigcomstock Jul 10, 2025
3a8cf6c
limit to 3 builds in history
craigcomstock Jul 10, 2025
6f42282
try to refactor to use a list of repos to checkout and generate the s…
craigcomstock Jul 10, 2025
b43eac4
fixup structure
craigcomstock Jul 10, 2025
93f8822
fix quotes to allow variable expansion?
craigcomstock Jul 10, 2025
bf1fd35
do comments work? and if so, added a todo
craigcomstock Jul 10, 2025
39d6179
added see what cloned and build stages
craigcomstock Jul 10, 2025
68bfaf6
get our bearings of where we are when building and running shell comm…
craigcomstock Jul 10, 2025
48f909b
try to refactor as scripted pipeline to gain access to checkout scm f…
craigcomstock Jul 10, 2025
2e6f60f
checkout documentation into a subdir
craigcomstock Jul 10, 2025
7628b6e
try to find the right place for options
craigcomstock Jul 10, 2025
e17d152
try to get both pipeline with buildDiscarder and node items working
craigcomstock Jul 10, 2025
92475ee
try to use the snippet generator to set 3 builds to keep in a scripte…
craigcomstock Jul 10, 2025
32817e2
fix syntax of buildDiscarder property
craigcomstock Jul 10, 2025
ba9721e
remove steps item as it is not needed in a scripted pipeline
craigcomstock Jul 10, 2025
6cec041
FP4
craigcomstock Jul 10, 2025
e15e9cb
add hard-coded BRANCH env var for master
craigcomstock Jul 10, 2025
d9f38d1
try to clean workspaces on success
craigcomstock Jul 10, 2025
a9887a8
add needed environment variables hard coded for now
craigcomstock Jul 10, 2025
1063ede
add withEnv in the right location, under node and enclosing stage
craigcomstock Jul 10, 2025
81ada4e
move cleanWS to a stage instead of at the node level
craigcomstock Jul 10, 2025
47b60ba
added needed PACKAGE_UPLOAD_DIRECTORY env var with a temp value
craigcomstock Jul 10, 2025
e22a9f7
added needed env var PACKAGE_BUILD=1
craigcomstock Jul 10, 2025
0eca7cb
add a working ubu22hub providing PACKAGE_UPLOAD_DIRECTORY
craigcomstock Jul 10, 2025
ffa04d4
save output as artifact
craigcomstock Jul 10, 2025
7538918
refactored repo checkout to include nice data structure for multi-org…
craigcomstock Jul 10, 2025
fc6500c
fixup a million-ish curly braces, thanks groovy
craigcomstock Jul 10, 2025
4494965
cross fingers
craigcomstock Jul 10, 2025
6ae6b5a
complicated, should push this checkout code to a library somehow
craigcomstock Jul 10, 2025
22ff9f9
restore archiving artifacts
craigcomstock Jul 11, 2025
469aabb
Explain a bit what generator/build/run.sh script does and what it pro…
craigcomstock Jul 11, 2025
4f7fb24
Try to add parameters as in fast-build-and-deploy-docs-master job
craigcomstock Jul 11, 2025
65b2f55
simplify clean workspace to always clean
craigcomstock Jul 11, 2025
0e60489
fixup properties
craigcomstock Jul 11, 2025
cb61686
FP4
craigcomstock Jul 11, 2025
084e081
FP4
craigcomstock Jul 11, 2025
049ee1b
FP4
craigcomstock Jul 11, 2025
eebf0cf
next try, push values into shell, parse there to center logic in repo…
craigcomstock Aug 6, 2025
475350d
FP4
craigcomstock Aug 6, 2025
a72f24d
FP4
craigcomstock Aug 6, 2025
7c2a52f
FP4
craigcomstock Aug 6, 2025
9f903f2
FP4
craigcomstock Aug 6, 2025
7882683
FP4
craigcomstock Aug 6, 2025
8662124
FP4
craigcomstock Aug 6, 2025
df45efd
FP4
craigcomstock Aug 6, 2025
2612c45
FP4
craigcomstock Aug 6, 2025
0082b98
FP4
craigcomstock Aug 6, 2025
a7d08d9
FP4
craigcomstock Aug 6, 2025
027051f
FP4
craigcomstock Aug 6, 2025
57ad9d5
FP4
craigcomstock Aug 6, 2025
e18a9f3
FP4
craigcomstock Aug 6, 2025
891dcf6
FP4
craigcomstock Aug 6, 2025
a8e0c15
FP4
craigcomstock Aug 6, 2025
9ae0dec
FP4
craigcomstock Aug 6, 2025
276c3cc
test out enterprise git access
craigcomstock Aug 6, 2025
a7e23e9
FP4
craigcomstock Aug 6, 2025
1d2d4bb
FP4
craigcomstock Aug 6, 2025
d294162
FP4
craigcomstock Aug 6, 2025
57969a8
FP4
craigcomstock Aug 6, 2025
5905ce8
wip jenkinsfile changes
craigcomstock Aug 6, 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
29 changes: 29 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pipeline {
agent { label 'CONTAINERS' }
environment {
REPOS = "core enterprise nova masterfiles"
BASE_BRANCH = "master"
}
stages {
stage('Check environment'){
steps {
sh "env"
sh "echo env CHANGE_ID: ${env.CHANGE_ID}"
sh "echo \"${pullRequest.title}\" > pull-request-title"
sh "echo \"${pullRequest.body}\" > pull-request-body"
sh "pwd; ls; whoami; uname -a"
sh "wget https://raw.githubusercontent.com/cfengine/buildscripts/refs/heads/master/ci/create-revisions-file.sh"
sh "./create-revisions-file.sh"
sh "wget https://gitlab.com/Northern.tech/OpenSource/GODS/-/raw/master/parallel_git_rev_fetch.sh"
sh "chmod u+x ./parallel_git_rev_fetch.sh"
withCredentials([sshUserPrivateKey(credentialsId:"autobuild", keyFileVariable: "key")]) {
sh 'GIT_SSH_COMMAND="ssh -i $key" ./parallel_git_rev_fetch.sh revisions'
# problem: does rev_fetch expect to be at the "top-level dir?"
}
sh 'cd ..; BRANCH=${DOCS_BRANCH} bash -x documentation/generator/build/run.sh'
}
}
}
}

todo: publish-over-ssh
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.PHONY: check
.PHONY: check build
check:
shellcheck generator/build/*.sh

build:

# wget https://gitlab.com/Northern.tech/OpenSource/GODS/-/raw/master/parallel_git_rev_fetch.sh
chmod u+x ./parallel_git_rev_fetch.sh
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
Loading