Bitbucket token using in bitbucket pipelines (Authentification issue) - bitbucket

i am trying to run pipeline on bitbucket, for my nodejs app, and i have some issue on deployment step (aws ec2). Pipeline runs in container, ssh-ing to my instance on aws, and then try to git clone my app, by command
git clone https://my_bitbucketusername:my_bitbuckettoken#bitbucket.org/somevendor/somerepo
but it is not good option to provide token in script, so i tried to set token as repository variable like $BITBUCKET_TOKEN,
git clone https://my_bitbucketusername:$BITBUCKET_TOKEN#bitbucket.org/somevendor/somerepo
but then i faced with bitbucket failed authentification. Same issue on gitlab, whad i do wrong?

Related

Jenkins freestyle project using Gitlab API Token never clone the repository, no error, build always succeed

I've followed this gitlab tutorial link, to connect my jenkins server to Gitlab.
Everyting went fine, and I've :
created a personnal access token in my GitLab profile
created a GitLab API Token using the my GitLab access token in jenkins system configuration as stated in the tutorial
create a freestyle jenkins job and Choose my GitLab connection from the dropdown
checked the Build when a change is pushed to GitLab checkbox.
checked the Accepted Merge Request Events and Closed Merge Request Events checkboxes
generated a secret token from the above freestyle project
use the freestyle jenkins project secret token to create a webhook in the GitLab project repository integration settings
Till there everything went fine.
Then I added and push code including a jenkinsFile to my GitLab repository, and get to the Jenkins WebUI to view the build status, but the pipeline shown green saying build success, while nothing happened, no code has been retrieved from GitLab (as shown in the attached console output screenshot), thus no jenkinsFile executed nor error message shown.
I tried to run the buils manually from WebUI but same result, no way to trigger my pipeline on git push events from GitLab
I thought may be I should select Git in Source Code Management section (I left it to None as the tutorial doesn't mention it) but if I choose Git as SCM I cannot select my GitLab API Token credentials, seeming like we cannot use GitLab plugin (API Token) and Git plugin for the same build project.
SO how should I proceed to be able build my jenkins project from GitLab with a jenkinsFile, using GitLab API Token?
Does the GitLab tutorial miss some useful steps?
OK, I think I understand the issue now.
There are two sets of credentials: GitLab API token for access to GitLab Webhooks and a separate one for cloning the git repo during builds.
So we can't use the GitLab API token for cloning the repository. For this you have to use either a SSH key or a Username/Password combination. Furthermore this dropdown is part of the git plugin not the gitlab plugin.
So the gitlab plugin can't tell which credentials are available as credentials for this dropdown.

Jenkins Build Trigger after each commit to Github

I want to set in Jenkins jobs triggering Build after each commit
I dont have access to Setting in my repository on Github, so I don't have possibility using WebHook.
What is the best/.easy way to set this in other way?
I have jobs for private repository Github, and clone project by SSH
I also using Github Oauth Token
Jenkins Continuous Integration Server is on running on a Ubuntu host
You can use local git hook pre-push. It runs after you issue the "git push" command. (but executes before pushing)
See example: pre-push hook

Triggering Multi Branch Pipeline Jenkins job using the git webhook not working

I have a multi branch pipeline job that is configured like this:
Polling is also configured for it:
When new commits are pushed to its configured Git repo, after polling, the Job is triggered as expected. In the console output the Git repo is logged as https://stash.example.com/scm/eg/project.git.
However when I try to trigger the job using the git notifyCommit webhook, I get this error message:
$ curl 'http://jenkins.example.com/git/notifyCommit?url=https://stash.example.com/scm/eg/project.git'
No git jobs using repository: https://stash.example.com/scm/eg/project.git and branches:
No Git consumers using SCM API plugin for: https://stash.example.com/scm/eg/project.git
What is missing here? Why Jenkins cannot find any jobs/git consumers for this repo to trigger it?
The reason you are getting that error is that you are using BitBucket Plugin in your job configuration so you can't you get notify endpoint to trigger builds using curl request. Also, GitNotify endpoint is part of Github plugin which scans all the job configuration which has used GitPlugin and then it cross-matched the URL of the curl request with the URL od repo used in git plugin. So, If you want to use bitbucket then follow the Instruction Documented on https://mohamicorp.atlassian.net/wiki/spaces/DOC/pages/381419546/Configuring+Webhook+To+Jenkins+for+Bitbucket+Bitbucket+Branch+Source+Plugin

Uploading projects from local computer to server by using Gitlab

I am completely new to Gitlab because previously I upload project to server using Filezilla. But now I have finished my Laravel projects in my local computer, and I would like to upload it to my could hosting. Currently my project is stored in c:\\xampp\htdocs\myproject.
Please tell me command line step-by-step to achieve this? I am using Putty on window. I can't understand it by reading existing tutorial.
I use DigitalOcean.com's server and yes I registered on gitlab.com to store/upload my project.
As a first approach, you can push directly to DigitalOcean, as describe in this tutorial:
clone your GitLab repo as a bare repo on your DigitalOcean instance (VPS: Virtual Private Server or Droplet)
cd
git clone --bare https://gitlab.com/<yourUsername>/<yourRepo.git>
add a post-receive hook similar to this auto-deploy article
That is:
cat > /home/rails/rails_project.git/hooks/post-receive
(Copy-paste the following lines)
#!/bin/sh
echo "-----------------------------------"
echo "Post receive hook: Updating website"
export GIT_WORK_TREE=/path/to/yourProject
export GIT_DIR=/home/yourUser/yourRepo.git
cd $GIT_WORK_TREE
git pull
git checkout master -f
(type Ctrl+D to exit)
Depending on your deployment path, you might have to execute the git commands as root, but it is best if you can keep your deployment as your username and not root.
But if you don't want to push to DigitalOcean, only to GitLab, you can use instead Git-Auto-Deploy.
Then you can push to GitLab, and that will trigger a deployment to your VPS.
When commits are pushed to your Git repository, the Git server will notify Git-Auto-Deploy by sending a HTTP POST request with a JSON body to a pre configured URL (your-host:8001).
The JSON body contains detailed information about the repository and what event that triggered the request.
Git-Auto-Deploy parses and validates the request, and if all goes well it issues a git pull.
Additionally, Git-Auto-Deploy can be configured to execute a shell command upon each successful git pull, which can be used to trigger custom build actions or test scripts.

Git plugin for Jenkins doesn't work with BitBucket repository

I have a project on bitbucket with git repository.
I want Jenkins job that pulls stuff from that repository. So I installed the Git Plugin.
I configure My Jenkins job to use git repository. I add credentials I use on BitBucket. Then I enter repository URL like this:
https://PawelRoman#bitbucket.org/PawelRoman/myproject.git
I'm getting the following error in red:
Failed to connect to repository : Failed to connect to https://PawelRoman#bitbucket.org/PawelRoman/myproject.git using credentials PawelRoman on BitBucket (status = 401)
401 seems like an authorization issue, but what can possibly be wrong? When I run git clone command manually from the server where I have Jenkins installed, using exactly the same repo URL and exactly the same credentials - it works without any issue. I am 100% sure the credentials are OK and repository URL is fine. How can I track down the cause of the issue?
Found out what the issue was. Repository URL was incorrect. For some reason jenkins git plugin does not allow for Username# in the repository URL.
So instead of https://PawelRoman#bitbucket.org/PawelRoman/myproject.git
You need to use
https://bitbucket.org/PawelRoman/myproject.git
And it will work.
User this url to get the project from the bitbucket
https://<user>:<pass>#bitbucket.org/<user>/<project>.git

Resources