Skip to content

Commit

Permalink
- bunch of fixex,
Browse files Browse the repository at this point in the history
- changed name of project
  • Loading branch information
gocruncher committed Sep 15, 2020
1 parent c1c14b7 commit 6746e5a
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 475 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
/vendor/
/release/
todo
jbuilder
jenkins-job-ctl
/trush/
/_build/
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NAME=jbuilder
NAME=jenkins-job-ctl
VERSION=$(shell cat VERSION)
BUILD=$(shell git rev-parse --short HEAD)
EXT_LD_FLAGS="-Wl,--allow-multiple-definition"
Expand All @@ -9,22 +9,22 @@ clean:

build:
go mod download
CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o jbuilder
CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o jenkins-job-ctl

build-dev:
go build -ldflags "-w -X main.version=$(VERSION)-dev -X main.build=$(BUILD) -extldflags=$(EXT_LD_FLAGS)"

build-all:
mkdir -p _build
GOOS=darwin GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jbuilder-$(VERSION)-darwin-amd64
GOOS=linux GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jbuilder-$(VERSION)-linux-amd64
GOOS=linux GOARCH=arm go build -tags release -ldflags $(LD_FLAGS) -o _build/jbuilder-$(VERSION)-linux-arm
GOOS=linux GOARCH=arm64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jbuilder-$(VERSION)-linux-arm64
GOOS=windows GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jbuilder-$(VERSION)-windows-amd64
GOOS=darwin GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jenkins-job-ctl-$(VERSION)-darwin-amd64
GOOS=linux GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jenkins-job-ctl-$(VERSION)-linux-amd64
GOOS=linux GOARCH=arm go build -tags release -ldflags $(LD_FLAGS) -o _build/jenkins-job-ctl-$(VERSION)-linux-arm
GOOS=linux GOARCH=arm64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jenkins-job-ctl-$(VERSION)-linux-arm64
GOOS=windows GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/jenkins-job-ctl-$(VERSION)-windows-amd64
cd _build; sha256sum * > sha256sums.txt

image:
docker build -t jbuilder -f Dockerfile .
docker build -t jenkins-job-ctl -f Dockerfile .

release:
mkdir release
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ An execution will be like this:
![terminal demo](assets/demo.gif)

## Install
Fetch the [latest release](https://github.com/gocruncher/jbuilder/releases) for your platform:
Fetch the [latest release](https://github.com/gocruncher/jenkins-job-ctl/releases) for your platform:

#### Linux

```bash
sudo wget https://github.com/gocruncher/jbuilder/releases/download/v1.0.1/jbuilder-1.0.1-linux-amd64 -O /usr/local/bin/jb
sudo chmod +x /usr/local/bin/jb
sudo wget https://github.com/gocruncher/jenkins-job-ctl/releases/download/v1.0.1/jenkins-job-ctl-1.0.1-linux-amd64 -O /usr/local/bin/jj
sudo chmod +x /usr/local/bin/jj
```

#### OS X brew

```bash
brew tap gocruncher/tap
brew install jb
brew install jj
```
#### OS X bash
```bash
sudo curl -Lo /usr/local/bin/jb https://github.com/gocruncher/jbuilder/releases/download/v1.0.1/jbuilder-1.0.1-darwin-amd64
sudo chmod +x /usr/local/bin/jb
sudo curl -Lo /usr/local/bin/jj https://github.com/gocruncher/jenkins-job-ctl/releases/download/v1.0.1/jenkins-job-ctl-1.0.1-darwin-amd64
sudo chmod +x /usr/local/bin/jj
```

## Getting Started

### Configure Access to Multiple Jenkins

```bash
jb set dev_jenkins --url "https://myjenkins.com" --login admin --token 11aa0926784999dab5
jj set dev_jenkins --url "https://myjenkins.com" --login admin --token 11aa0926784999dab5
```
where the token is available in your personal configuration page of the Jenkins. Go to the Jenkins Web Interface and click your name on the top right corner on every page, then click "Configure" to see your API token.

In case, when Jenkins is available without authorization:
```bash
jb set dev_jenkins --url "https://myjenkins.com"
jj set dev_jenkins --url "https://myjenkins.com"
```

or just run the following command in dialog execution mode:
```bash
jb set dev_jenkins
jj set dev_jenkins
```


Expand All @@ -53,29 +53,29 @@ jb set dev_jenkins
As a recommendation, you can enable shell autocompletion for convenient work. To do this, run following:
```bash
# for zsh completion:
echo 'source <(jb completion zsh)' >>~/.zshrc
echo 'source <(jj completion zsh)' >>~/.zshrc

# for bash completion:
echo 'source <(jb completion bash)' >>~/.bashrc
echo 'source <(jj completion bash)' >>~/.bashrc
```
if this does not work for some reason, try following command that might help you to figure out what is wrong:
```bash
jb completion check
jj completion check
```

### Examples
```bash
# Configure Access to the Jenkins
jb set dev-jenkins
jj set dev-jenkins

# Start 'app-build' job in the current Jenkins
jb run app-build
jj run app-build

# Start 'web-build' job in Jenkins named prod
jb run -n prod web-build
jj run -n prod web-build

# makes a specific Jenkins name by default
jb use PROD
jj use PROD
```

## Futures
Expand All @@ -93,4 +93,4 @@ jb use PROD
- support of a terminal window resizing

## License
`Jbuilder` is open-sourced software licensed under the [MIT](LICENSE) license.
`jenkins-job-ctl` is open-sourced software licensed under the [MIT](LICENSE) license.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.1.0
14 changes: 7 additions & 7 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ https://itnext.io/upgrading-bash-on-macos-7138bd1066ba
`, ver)
return
}
fmt.Println("Checked. After reloading your shell, jb autocompletion should be working.")
fmt.Println("Checked. After reloading your shell, jj autocompletion should be working.")
}

func checkZsh() {
Expand All @@ -130,16 +130,16 @@ func checkZsh() {
fmt.Println(
`
Error: ~/.zshrc file was not found. As the next step, please create file and add the following line:
source <(jb completion zsh)`)
source <(jj completion zsh)`)
return
}
fmt.Println("==> file ~/.zshrc is exist - OK")
if !strings.Contains(buffer.String(), "jb completion zsh") {
if !strings.Contains(buffer.String(), "jj completion zsh") {
fmt.Println("==> completion script has not been added - FAILED")
fmt.Println(
`
Error: ~/.zshrc should have line with jb completion script for the shell. Make sure, that the following line has been added the the ~/.zshrc file:
source <(jb completion zsh)`)
Error: ~/.zshrc should have line with jj completion script for the shell. Make sure, that the following line has been added the the ~/.zshrc file:
source <(jj completion zsh)`)
return
}
fmt.Println("==> completion script has been added - OK")
Expand All @@ -152,7 +152,7 @@ Error: ~/.zshrc should have line with jb completion script for the shell. Make s
rsp, _ := ioutil.ReadAll(stderr)
if strings.Contains(string(rsp), "not found") {
compinitPos := strings.Index(buffer.String(), "autoload -Uz compinit")
scriptPos := strings.Index(buffer.String(), "jb completion zsh")
scriptPos := strings.Index(buffer.String(), "jj completion zsh")
if compinitPos > -1 && compinitPos > scriptPos {
fmt.Println("==> the initialized compdef script was added incorrectly - FAILED")
fmt.Println(
Expand All @@ -174,5 +174,5 @@ Error: current shell does not have required 'compdef' function. Add the followin
}
fmt.Println("==> compdef functions is exist - OK")

fmt.Println("Checked. After reloading your shell, jb autocompletion should be working.")
fmt.Println("Checked. After reloading your shell, jj autocompletion should be working.")
}
8 changes: 4 additions & 4 deletions cmd/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"fmt"
"github.com/ASalimov/jbuilder/cmd/jb"
"github.com/gocruncher/jenkins-job-ctl/cmd/jj"
"github.com/spf13/cobra"
)

Expand All @@ -21,21 +21,21 @@ func del(args []string) {
if len(args) == 0 {
fmt.Println("which Jenkins should be removed?")
choices := []string{}
for _, e := range jb.GetEnvs() {
for _, e := range jj.GetEnvs() {
choices = append(choices, string(e.Name))
}
for {

name := getAnswer("name: ", "", choices)
if err := jb.DelEnv(jb.EName(name)); err != nil {
if err := jj.DelEnv(jj.EName(name)); err != nil {
fmt.Println(err)
continue
}
fmt.Println("Removed.")
return
}
}
if err := jb.DelEnv(jb.EName(args[0])); err != nil {
if err := jj.DelEnv(jj.EName(args[0])); err != nil {
fmt.Println(err)
} else {
fmt.Println("Removed.")
Expand Down
18 changes: 9 additions & 9 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd

import (
"fmt"
"github.com/ASalimov/jbuilder/cmd/jb"
"github.com/gocruncher/jenkins-job-ctl/cmd/jj"
"github.com/spf13/cobra"
"os"
"regexp"
Expand Down Expand Up @@ -51,7 +51,7 @@ var (
func init() {

annotation := make(map[string][]string)
annotation[cobra.BashCompCustom] = []string{"__jb_get_env"}
annotation[cobra.BashCompCustom] = []string{"__jj_get_env"}

//flag := &pflag.Flag{
// Name: "env",
Expand All @@ -64,7 +64,7 @@ func init() {
Short: "Display any resources(settings, jobs)",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 && ENV != "" {
showAllJobs(jb.Init(ENV))
showAllJobs(jj.Init(ENV))
os.Exit(0)
}
if len(args) > 1 && args[0] == "compline" {
Expand All @@ -76,7 +76,7 @@ func init() {
s1 := strings.Split(s[i+3:], " ")
showJobs(strings.TrimSpace(s1[0]))
} else {
showJobs(string(jb.GetDefEnv()))
showJobs(string(jj.GetDefEnv()))
}
os.Exit(0)
}
Expand All @@ -91,7 +91,7 @@ func init() {
getCmd.Flags().BoolVar(&noheader, "no-headers", false, "no-headers")
getCmd.Flags().StringVarP(&ENV, "name", "n", "", "current Jenkins name")
//getCmd.Flags().StringVarP(&ENV, "env", "e", "", "")
//for _, env:=range jb.GetEnvs(){
//for _, env:=range jj.GetEnvs(){
// curEnv:=env
// var envCmd = &cobra.Command{
// Use: string(env.Name),
Expand All @@ -115,7 +115,7 @@ func showJobs(eName string) {
// Run your long running function in it's own goroutine and pass back it's
// response into our channel.
go func() {
env := jb.Init(eName)
env := jj.Init(eName)
showAllJobs(env)
ch <- struct{}{}
}()
Expand All @@ -135,21 +135,21 @@ func showAllEnvs() {
if !noheader {
fmt.Fprintf(w, "%s\t%s\t%s\n", "Name", "URL", "Authorization")
}
for _, e := range jb.GetEnvs() {
for _, e := range jj.GetEnvs() {
fmt.Fprintf(w, "%s\t%s\t%s\n", e.Name, e.Url, e.Type)
}
fmt.Fprintln(w)
w.Flush()
}

func showAllJobs(env jb.Env) {
func showAllJobs(env jj.Env) {
w := new(tabwriter.Writer)
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
if !noheader {
fmt.Fprintf(w, "%s\t%s\n", "Name", "URL")
}
for _, view := range jb.GetBundle(env).Views {
for _, view := range jj.GetBundle(env).Views {
//fmt.Printf("views: %+v",view)
for _, j := range view.Jobs {
fmt.Fprintf(w, "%s\t%s\n", j.Name, j.URL)
Expand Down
4 changes: 2 additions & 2 deletions cmd/jb/jb.go → cmd/jj/jb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jb
package jj

import (
"crypto/tls"
Expand Down Expand Up @@ -30,7 +30,7 @@ var ErrNoJob = errors.New("no job")

func init() {
homeDir, _ = os.UserHomeDir()
homeDir = homeDir + "/.jb/"
homeDir = homeDir + "/.jj/"
initConfig()
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/jb/jb_api.go → cmd/jj/jb_api.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jb
package jj

import (
"encoding/json"
Expand Down
7 changes: 1 addition & 6 deletions cmd/jb/jb_test.go → cmd/jj/jb_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jb
package jj

import (
"fmt"
Expand Down Expand Up @@ -29,11 +29,6 @@ func TestGetLastSuccessfulBuildDuration(t *testing.T) {
fmt.Println("jd ", rsp)
}

func TestGetJobInfo(t *testing.T) {
ji := GetJobInfo(getEnv("pi"), "core-change-zone")
fmt.Printf("ji %+v", ji.GetParameterDefinitions())
}

func TestCancelJob(t *testing.T) {
status, err := CancelJob(getEnv("uat"), "web-rpm-build-manual", 40)
assert.NoError(t, err)
Expand Down
Loading

0 comments on commit 6746e5a

Please sign in to comment.