在 Debian 上运行的 Jenkins 中创建任务(Job/Item)的一般步骤如下,适用于大多数版本(Jenkins 2.x):
Jenkins 已安装并运行
systemctl status jenkins
浏览器访问:
http://<服务器IP>:8080
已登录 Jenkins
/var/lib/jenkins/secrets/initialAdminPassword 中的密码解锁my-debian-build
https://github.com/xxx/xxx.git常见选项:
H/5 * * * *
点击 增加构建步骤,常见选择:
Debian 示例(执行 Shell)
#!/bin/bash
sudo apt update
sudo apt install -y build-essential
make
或运行测试:
pytest
target/*.jar
| 类型 | 适用场景 |
|---|---|
| Freestyle | 简单脚本、入门 |
| Pipeline | 复杂 CI/CD(推荐) |
| Maven Project | Java/Maven |
| Multibranch | 多分支 Git |
新建任务 → 选择 Pipeline
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'make'
}
}
stage('Test') {
steps {
sh 'make test'
}
}
}
}
Jenkins 默认以 jenkins 用户运行:
sudo usermod -aG sudo jenkins
或在 /etc/sudoers 中配置免密:
jenkins ALL=(ALL) NOPASSWD:ALL
如果你有 具体需求(如:构建 Debian 包、Docker、Python、自动部署),可以告诉我,我可以给你更精确的 Jenkins 任务配置示例。