-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwoodpecker-cli-trigger.sh
More file actions
executable file
·60 lines (49 loc) · 1.92 KB
/
woodpecker-cli-trigger.sh
File metadata and controls
executable file
·60 lines (49 loc) · 1.92 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
#!/bin/bash
# ABOUTME: Script to trigger Woodpecker builds using CLI
# ABOUTME: Alternative to UI for manual pipeline triggers
# Configuration (update these)
WOODPECKER_SERVER="${WOODPECKER_SERVER:-https://ci.yourdomain.com}"
WOODPECKER_TOKEN="${WOODPECKER_TOKEN:-your-personal-token}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Check if woodpecker-cli is installed
if ! command -v woodpecker-cli &> /dev/null; then
echo -e "${YELLOW}Installing Woodpecker CLI...${NC}"
# Detect OS and install accordingly
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
brew install woodpecker-cli
else
# Linux - download latest release
curl -L https://github.com/woodpecker-ci/woodpecker/releases/latest/download/woodpecker-cli_linux_amd64.tar.gz | tar xz
sudo mv woodpecker-cli /usr/local/bin/
fi
fi
# Export environment variables for woodpecker-cli
export WOODPECKER_SERVER
export WOODPECKER_TOKEN
# Get repository info
REPO_NAME=$(basename $(git rev-parse --show-toplevel))
REPO_OWNER=$(git remote get-url origin | sed 's/.*[:/]\([^/]*\)\/.*/\1/')
BRANCH=$(git branch --show-current)
echo -e "${BLUE}Repository: ${REPO_OWNER}/${REPO_NAME}${NC}"
echo -e "${BLUE}Branch: ${BRANCH}${NC}"
# List recent pipelines
echo -e "\n${YELLOW}Recent pipelines:${NC}"
woodpecker-cli pipeline ls "${REPO_OWNER}/${REPO_NAME}" --limit 5
# Trigger new build
echo -e "\n${YELLOW}Triggering new build...${NC}"
woodpecker-cli pipeline create "${REPO_OWNER}/${REPO_NAME}" "${BRANCH}"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Pipeline triggered successfully${NC}"
# Get the latest pipeline info
echo -e "\n${YELLOW}Latest pipeline status:${NC}"
woodpecker-cli pipeline last "${REPO_OWNER}/${REPO_NAME}"
else
echo -e "${RED}✗ Failed to trigger pipeline${NC}"
echo "Please check your WOODPECKER_SERVER and WOODPECKER_TOKEN environment variables"
fi