Merge branch 'develop' into ansible-instance
This commit is contained in:
commit
baa0da13a2
|
|
@ -1288,13 +1288,13 @@ the API access token and then it is straight forward:
|
|||
|
||||
SERVER="http://10.115.101.101:8080"
|
||||
COOKIEJAR="$(mktemp)"
|
||||
# replave <token> with the string of the generated token in the previous step:
|
||||
# replace <token> with the string of the generated token in the previous step:
|
||||
CRUMB=$(curl -u "developer:<token>" --cookie-jar "$COOKIEJAR" "$SERVER/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)")
|
||||
|
||||
# trigger build with default parameters:
|
||||
# trigger build with default job parameters:
|
||||
curl -X POST -u "developer:<token>" --cookie "$COOKIEJAR" -H "$CRUMB" "$SERVER"/job/doc-pipeline/buildWithParameters?token=buildDocToken
|
||||
|
||||
# trigger build with specific parameters:
|
||||
# trigger build with specific job parameters:
|
||||
curl -X POST -u "developer:<token>" --cookie "$COOKIEJAR" -H "$CRUMB" "$SERVER"/job/doc-pipeline/buildWithParameters?token=buildDocToken --data VERSION="0.0.2" --data DO_CLEAN_BUILD=true
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2148,6 +2148,208 @@ With this change we create a new version of the NWL docker instance:
|
|||
./manage.sh --image=nwl-env-ci:0.3.2 --branch=main --name=nwl_0_3_2 --platform=nwl --config=/home/user/work/ci/config/config.xml --revision=0.3.2 --maintainer=TeamCHBE create
|
||||
|
||||
|
||||
Commit and Pushing Changes
|
||||
**************************
|
||||
In general it is not possible to push directly to branch main. Thus, we need to go over a merge/pull request which we
|
||||
can achieve with a REST API call. I found a helpful REST API look-up page
|
||||
`here <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-post>`_
|
||||
|
||||
From this page we get a template (cloud version) for our pull/merge request:
|
||||
|
||||
.. code-block::
|
||||
|
||||
curl --request POST \
|
||||
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests' \
|
||||
--header 'Authorization: Bearer <access_token>' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '{
|
||||
"type": "<string>",
|
||||
"links": {
|
||||
"self": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"html": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"commits": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"approve": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"diff": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"diffstat": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"comments": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"activity": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"merge": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
},
|
||||
"decline": {
|
||||
"href": "<string>",
|
||||
"name": "<string>"
|
||||
}
|
||||
},
|
||||
"id": 108,
|
||||
"title": "<string>",
|
||||
"rendered": {
|
||||
"title": {
|
||||
"raw": "<string>",
|
||||
"markup": "markdown",
|
||||
"html": "<string>"
|
||||
},
|
||||
"description": {
|
||||
"raw": "<string>",
|
||||
"markup": "markdown",
|
||||
"html": "<string>"
|
||||
},
|
||||
"reason": {
|
||||
"raw": "<string>",
|
||||
"markup": "markdown",
|
||||
"html": "<string>"
|
||||
}
|
||||
},
|
||||
"summary": {
|
||||
"raw": "<string>",
|
||||
"markup": "markdown",
|
||||
"html": "<string>"
|
||||
},
|
||||
"state": "OPEN",
|
||||
"author": {
|
||||
"type": "<string>"
|
||||
},
|
||||
"source": {
|
||||
"repository": {
|
||||
"type": "<string>"
|
||||
},
|
||||
"branch": {
|
||||
"name": "<string>",
|
||||
"merge_strategies": [
|
||||
"merge_commit"
|
||||
],
|
||||
"default_merge_strategy": "<string>"
|
||||
},
|
||||
"commit": {
|
||||
"hash": "<string>"
|
||||
}
|
||||
},
|
||||
"destination": {
|
||||
"repository": {
|
||||
"type": "<string>"
|
||||
},
|
||||
"branch": {
|
||||
"name": "<string>",
|
||||
"merge_strategies": [
|
||||
"merge_commit"
|
||||
],
|
||||
"default_merge_strategy": "<string>"
|
||||
},
|
||||
"commit": {
|
||||
"hash": "<string>"
|
||||
}
|
||||
},
|
||||
"merge_commit": {
|
||||
"hash": "<string>"
|
||||
},
|
||||
"comment_count": 51,
|
||||
"task_count": 53,
|
||||
"close_source_branch": true,
|
||||
"closed_by": {
|
||||
"type": "<string>"
|
||||
},
|
||||
"reason": "<string>",
|
||||
"created_on": "<string>",
|
||||
"updated_on": "<string>",
|
||||
"reviewers": [
|
||||
{
|
||||
"type": "<string>"
|
||||
}
|
||||
],
|
||||
"participants": [
|
||||
{
|
||||
"type": "<string>"
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
.. note::
|
||||
Currently we do not have a specific NetModule CI user (located in the AD) as we have had for the OEM Linux CI and
|
||||
in addition we do not want to add username and password in a REST API call. So, we will create a project specific
|
||||
HTTP access token. This would limit the access to only this repository and not to all of the repositories that a
|
||||
user would have. See next sections about how the PR is finally set up.
|
||||
|
||||
|
||||
Create HTTP Access Token
|
||||
========================
|
||||
The following steps guide you through the setup of a HTTP access token.
|
||||
|
||||
#. Browse on Bitbucket to the repository `Netmodule Wireless Linux <https://bitbucket.gad.local/projects/NM-NSP/repos/netmodule-wireless-linux/browse>`_
|
||||
#. Within the *repository settings* select *HTTP access tokens*
|
||||
#. Create a token:
|
||||
|
||||
#) Press *Create token*
|
||||
#) Enter a name for the token, e.g. *CI user*
|
||||
#) Select *write* for the repository permissions
|
||||
#) OPTIONAL: Set an expiration time in days
|
||||
#) Press *Create*
|
||||
#) IMPORTANT: Store the generated token to a secure place like KeePass database or similar
|
||||
|
||||
#. The generated token will be used for the REST API call, see next section
|
||||
|
||||
|
||||
Create Merge/Pull Request over REST API
|
||||
=======================================
|
||||
Once we have pushed our changes to the branch *nightly* we can create a pull request using the HTTP access token from
|
||||
the section before:
|
||||
|
||||
.. code-block::
|
||||
|
||||
curl --request POST \
|
||||
--url 'https://bitbucket.gad.local/rest/api/1.0/projects/NM-NSP/repos/netmodule-wireless-linux/pull-requests' \
|
||||
--header 'Authorization: Bearer <ACCESS_TOKEN>' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '<PR_DATA_JSON>'
|
||||
|
||||
# where
|
||||
# - <ACCESS_TOKEN>: the access token you stored at creation time in section `Create HTTP Access Token`
|
||||
# - <PR_DATA_JSON>:
|
||||
# { "title": "Nightly: Src Rev Update", \
|
||||
# "description": "CI is ppdating the source revisions to HEAD", \
|
||||
# "state": "OPEN", "open": true, "closed": false, \
|
||||
# "fromRef": { "id": "refs/heads/nightly", \
|
||||
# "repository": {"slug": "netmodule-wireless-linux", "name": null, "project": {"key": "NM-NSP"}} \
|
||||
# }, \
|
||||
# "toRef": { "id": "refs/heads/main", \
|
||||
# "repository": {"slug": "netmodule-wireless-linux", "name": null, "project": {"key": "NM-NSP"}} \
|
||||
# }, \
|
||||
# "locked": false,\
|
||||
# "reviewers": [{"user": {"name": "bard"}}], "links": {"self": [null]} \
|
||||
# }
|
||||
|
||||
.. note::
|
||||
* The REST API URL version is different to the template we have seen before. I did not find an example for data
|
||||
center version with 2.0, thus I don't know if 2.0 is working
|
||||
* Alexandre Bard (bard) is set as default reviewer
|
||||
|
||||
|
||||
Nightly Trigger Integration
|
||||
###########################
|
||||
With the Job DSL plugin version 1.77 the option ``triggers`` is deprecated and will be removed soon (reason: it caused
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pipeline {
|
|||
|
||||
parameters {
|
||||
string(name: 'BUILD_BRANCH', defaultValue: 'main', description: 'Enter the branch of the NWL to build (default = main), will skip deployment if not main')
|
||||
booleanParam(name: 'CLEAN_BUILD', defaultValue: false, description: 'do a clean build, i.e. remove the yocto directory and start from scratch')
|
||||
booleanParam(name: 'CLEAN_BUILD', defaultValue: true, description: 'do a clean build, i.e. remove the yocto directory and start from scratch')
|
||||
booleanParam(name: 'DRY_RUN', defaultValue: true, description: 'do a dry run, i.e. without committing and pushing')
|
||||
}
|
||||
|
||||
|
|
@ -91,14 +91,57 @@ def updateTheSourceRevisions(commonHelpers, repoDir, theBranch) {
|
|||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
def setupNewBranchAndGetGitPushPostfix(theNewBranch) {
|
||||
if(sh(returnStatus: true, script: "git checkout ${theNewBranch}") == 0) {
|
||||
println "----------------------------------------------------\n\
|
||||
NOTE: Branch ${theNewBranch} already available \n\
|
||||
and potentially as well a pull/merge request.\n\
|
||||
--> handle this branch and request first\n----------------------------------------------------"
|
||||
error("Available branch ${theNewBranch} detected --> handle this first")
|
||||
}
|
||||
|
||||
sh(script: "git checkout -b ${theNewBranch}")
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
def createPR(theBranch) {
|
||||
def prReviewer = "bard"
|
||||
def prProject = "NM-NSP"
|
||||
def prRepo = "netmodule-wireless-linux"
|
||||
|
||||
def bitbucketRestApiUrl = "https://bitbucket.gad.local/rest/api/1.0"
|
||||
def prTitle = "Nightly: Src Rev Update"
|
||||
def prDescription = "CI is ppdating the source revisions to HEAD"
|
||||
def prRepository = "\"repository\": {\"slug\": \"${prRepo}\", \"name\": null, \"project\": {\"key\": \"${prProject}\"}}"
|
||||
def prDataJson = "{\"title\": \"${prTitle}\", \"description\": \"${prDescription}\",\
|
||||
\"state\": \"OPEN\", \"open\": true, \"closed\": false,\
|
||||
\"fromRef\": {\"id\": \"refs/heads/${theBranch}\", ${prRepository}},\
|
||||
\"toRef\": {\"id\": \"refs/heads/main\", ${prRepository}},\
|
||||
\"locked\": false,\
|
||||
\"reviewers\": [{\"user\": {\"name\": \"${prReviewer}\"}}], \"links\": {\"self\": [null]}}"
|
||||
def prUrl = "${bitbucketRestApiUrl}/projects/${prProject}/repos/${prRepo}/pull-requests"
|
||||
def authHeader = "Authorization: Bearer MDI1NjczNzAyMTI3OrbDBQestfmsi/Iys5qvKP4Tgulp"
|
||||
def acceptHeader = "Accept: application/json"
|
||||
def contentHeader = "Content-Type: application/json"
|
||||
|
||||
def prResponse = sh(returnStdout: true,
|
||||
script: "curl --request POST --url '${prUrl}' \
|
||||
--header '${authHeader}' \
|
||||
--header '${acceptHeader}' \
|
||||
--header '${contentHeader}' \
|
||||
--data '${prDataJson}'").toString()
|
||||
if(prResponse.contains("error")) {
|
||||
error("Failed creating PR/MR:\n${prResponse}")
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
def commitAndPushTheChanges(commonHelpers, repoDir) {
|
||||
def commitMsg = "srcrev: updated source revisions by Jenkins Job"
|
||||
def nightlyBranch = "nightly"
|
||||
|
||||
dir(repoDir) {
|
||||
if(sh(returnStdout: true, script: "git status | grep \"modified:\" | grep -v coreos | wc -l").toInteger() != 0) {
|
||||
def itemFindCmd = "git status | grep \"modified:\" | grep -v coreos | cut -d':' -f2 | sed -e 's/^[ ]*//' | cut -d' ' -f1"
|
||||
def changedItems = sh(returnStdout: true, script: "${itemFindCmd}")
|
||||
sh(label: "Stage tracked and changed git files", returnStdout: true, script: "git add ${changedItems}")
|
||||
if(sh(returnStdout: true, script: "git status | grep \"modified:\" | wc -l").toInteger() != 0) {
|
||||
def changedItems = sh(returnStdout: true, script: "git status")
|
||||
sh(label: "Stage tracked and changed git files", returnStdout: true, script: "git add \\*")
|
||||
|
||||
if(params.DRY_RUN) {
|
||||
println "DRY RUN: commit message = '${commitMsg}'\n changes = ${changedItems}"
|
||||
|
|
@ -106,13 +149,19 @@ def commitAndPushTheChanges(commonHelpers, repoDir) {
|
|||
}
|
||||
else {
|
||||
def theCredentials = commonHelpers.getGitCredentialID()
|
||||
setupNewBranchAndGetGitPushPostfix("${nightlyBranch}")
|
||||
println "Commit and Push changes; message = '${commitMsg}'\nchanges = ${changedItems}"
|
||||
sshagent (credentials: [theCredentials]) {
|
||||
println "Commit and Push changes; message = '${commitMsg}'\nchanges = ${changedItems}"
|
||||
// ToDo: replace the user.email and user.name once a CI user is setup in the
|
||||
// active directory.
|
||||
sh(label: "Commit and push changes", returnStdout: true, script: """
|
||||
git config --global user.email "marc.mattmueller@netmodule.com"
|
||||
git config --global user.name "Marc Mattmüller"
|
||||
git commit -m "${commitMsg}"
|
||||
git push
|
||||
git push -u origin ${theNewBranch}
|
||||
""")
|
||||
}
|
||||
createPR("${nightlyBranch}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue