在 Jenkins 上部署 Debian 项目(通常指构建 .deb 包并部署到服务器或仓库),一般流程如下。下面按常见实战方式说明,适用于大多数 Debian / Ubuntu 项目。
确保 Jenkins 已安装并可用,并安装必要插件:
构建节点(Agent)需为 Debian / Ubuntu,并安装:
sudo apt update
sudo apt install -y build-essential debhelper devscripts dpkg-dev
一个标准 Debian 打包项目结构:
my-project/
├── debian/
│ ├── control
│ ├── rules
│ ├── changelog
│ └── install
├── src/
└── Makefile
pipeline {
agent any
environment {
DEBEMAIL = "jenkins@example.com"
DEBFULLNAME = "Jenkins"
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/your/repo.git'
}
}
stage('Build .deb') {
steps {
sh '''
dpkg-buildpackage -us -uc -b
'''
}
}
stage('Deploy') {
steps {
sshPublisher(
publishers: [
sshPublisherDesc(
configName: 'debian-server',
transfers: [
sshTransfer(
sourceFiles: '../*.deb',
remoteDirectory: '/tmp/deb/'
)
]
)
]
)
}
}
}
}
ssh user@server "dpkg -i /tmp/deb/xxx.deb || apt-get install -f -y"
使用 reprepro 或 aptly:
aptly repo add myrepo ../*.deb
aptly publish update stable
然后在目标服务器:
apt update
apt install my-project
systemctl restart my-project.service
✅ dpkg-buildpackage 必须在 源码根目录
✅ 版本号要在 debian/changelog 中更新
✅ 构建用户需要有写权限
✅ 依赖包必须写在 debian/control
代码提交 → Jenkins 拉取 → 构建 .deb → 上传/安装/入仓 → 完成
如果你愿意,可以告诉我:
我可以给你更精准的 Jenkins 配置示例。