-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile.bazel
More file actions
113 lines (103 loc) · 3.71 KB
/
Jenkinsfile.bazel
File metadata and controls
113 lines (103 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
pipeline {
agent any
environment {
PROJECT_NAME = 'bazel-python-demo'
}
stages {
stage('Checkout Code') {
steps {
echo 'Checking out Bazel Python code...'
checkout scm
}
}
stage('Setup Build Environment') {
steps {
echo 'Installing build tools and creating non-root user...'
sh '''
# Install build tools as root
apt-get update
apt-get install -y build-essential curl python3 python3-dev sudo
# Create a non-root user for Bazel
useradd -m -s /bin/bash bazeluser || echo "User already exists"
# Give bazeluser ownership of workspace
chown -R bazeluser:bazeluser /var/jenkins_home/workspace/
# Verify installations
gcc --version
python3 --version
echo "Build environment setup completed!"
'''
}
}
stage('Install Bazelisk') {
steps {
echo 'Installing Bazelisk as non-root user...'
sh '''
# Install Bazelisk as bazeluser
sudo -u bazeluser bash -c '
if ! command -v bazel &> /dev/null; then
echo "Installing Bazelisk..."
curl -L -o bazelisk "https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64"
chmod +x bazelisk
mkdir -p ~/bin
mv bazelisk ~/bin/bazel
export PATH="$HOME/bin:$PATH"
~/bin/bazel version
else
echo "Bazel is already installed."
bazel version
fi
'
'''
}
}
stage('Build Hello Target') {
steps {
echo 'Building the hello target as non-root user...'
sh '''
# Build as bazeluser
sudo -u bazeluser bash -c '
export PATH="$HOME/bin:$PATH"
cd $WORKSPACE
ls -la
echo "Looking for MODULE.bazel..."
find . -name "MODULE.bazel" -type f
bazel build //:hello
'
'''
}
}
stage('Run Application') {
steps {
echo 'Running the Python application...'
sh '''
# Run as bazeluser
sudo -u bazeluser bash -c '
export PATH="$HOME/bin:$PATH"
cd $WORKSPACE
bazel run //:hello
'
'''
}
}
}
post {
always {
echo 'Bazel pipeline completed!'
sh '''
sudo -u bazeluser bash -c '
export PATH="$HOME/bin:$PATH"
cd $WORKSPACE
bazel shutdown || true
' || true
'''
}
success {
echo 'Bazel build succeeded! 🎉'
echo 'Python application ran successfully with Bazel!'
}
failure {
echo 'Bazel build failed! ❌'
echo 'Check the logs above for details.'
}
}
}