Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use nil as type string in argument to gojenkins.CreateJenkins #189

Open
marionxue opened this issue Oct 22, 2019 · 4 comments
Open

Comments

@marionxue
Copy link

package main

import (
	"fmt"
	"github.com/bndr/gojenkins"
)


func GetNode(){

	jenkins:= gojenkins.CreateJenkins(nil, "http://jenkins.example.com", "username","password")

	nodes,err := jenkins.GetAllNodes()
	if err!=nil{
		panic(err)
	}
	for _,node := range nodes{
		node.Poll()
		online,err:=node.IsOnline()
		if err !=nil {
			panic(err)
		}

		if online{
			fmt.Printf("node is online Running...")
		}
		fmt.Printf(node.GetName())
	}


}

func main(){
	GetNode()
}

but. the output is

# command-line-arguments
./jenkinsclean.go:11:35: cannot use nil as type string in argument to gojenkins.CreateJenkins
./jenkinsclean.go:13:12: assignment mismatch: 2 variables but jenkins.GetAllNodes returns 1 values
@marionxue
Copy link
Author

@bndr can you help me to fix it?

@matthorgan
Copy link

matthorgan commented Oct 24, 2019

Due to the semantic version issue #174 , when you import the package, you're actually importing an old version. The old version actually only expects the base string and auth details like so:

jenkins:= gojenkins.CreateJenkins("http://jenkins.example.com", "username","password")

If you want to update to the very latest commit, you could do:

go get github.com/bndr/gojenkins@de43c03cf849dd63a9737df6e05791c7a176c93d

Note: Before the above command, you may have to run go clean --modcache to remove your module cache.

@marionxue
Copy link
Author

thx for your help. i have clean module cache and resolv my issue, but what the mean of ./jenkinsclean.go:11:35: cannot use nil as type string in argument to gojenkins.CreateJenkins. after to run my demos. the issue is still here.

@matthorgan
Copy link

Apologies, the latest commit is actually:

go get github.com/bndr/gojenkins@de43c03cf849dd63a9737df6e05791c7a176c93d

I've updated my first comment to reflect the correct commit.

I've also made the assumption you're using Go modules. If not, here are the complete steps:

  1. Navigate to your project directory and run go mod init <modulename> where <modulename> is whatever you want to call your module. This will create a go.mod and go.sum file in your project directory.
  2. Run go get github.com/bndr/gojenkins@de43c03cf849dd63a9737df6e05791c7a176c93d to import the Jenkins module at the latest commit (Nov 2018).
  3. You should now be able to run your code with no errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants